Show Curl POST Request Headers? Is there a way to do this?

前端 未结 5 537
情话喂你
情话喂你 2020-12-02 13:59

I\'m building a Curl web automation app and am having some issue with not getting the desired outcome of my POST action, I am having some trouble figuring out how I can show

相关标签:
5条回答
  • 2020-12-02 14:29

    You can make you request headers by yourself using:

    // open a socket connection on port 80
    $fp = fsockopen($host, 80);
    
    // send the request headers:
    fputs($fp, "POST $path HTTP/1.1\r\n");
    fputs($fp, "Host: $host\r\n");
    fputs($fp, "Referer: $referer\r\n");
    fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
    fputs($fp, "Content-length: ". strlen($data) ."\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    fputs($fp, $data);
    
    $result = ''; 
    while(!feof($fp)) {
        // receive the results of the request
        $result .= fgets($fp, 128);
    }
    
    // close the socket connection:
    fclose($fp);
    

    Like writen on how make request

    0 讨论(0)
  • 2020-12-02 14:35

    You can save all headers sent by curl to a file using :

    $f = fopen('request.txt', 'w');
    curl_setopt($ch,CURLOPT_VERBOSE,true);
    curl_setopt($ch,CURLOPT_STDERR ,$f);
    
    0 讨论(0)
  • 2020-12-02 14:43

    Here is all you need:

    curl_setopt($curlHandle, CURLINFO_HEADER_OUT, true); // enable tracking
    ... // do curl request    
    $headerSent = curl_getinfo($curlHandle, CURLINFO_HEADER_OUT ); // request headers
    
    0 讨论(0)
  • 2020-12-02 14:44

    You can see the information regarding the transfer by doing:

    curl_setopt($curl_exect, CURLINFO_HEADER_OUT, true);
    

    before the request, and

    $information = curl_getinfo($curl_exect);
    

    after the request

    View: http://www.php.net/manual/en/function.curl-getinfo.php

    You can also use the CURLOPT_HEADER in your curl_setopt

    curl_setopt($curl_exect, CURLOPT_HEADER, true);
    
    $httpcode = curl_getinfo($c, CURLINFO_HTTP_CODE);
    
    return $httpcode == 200;
    

    These are just some methods of using the headers.

    0 讨论(0)
  • 2020-12-02 14:51

    I had exactly the same problem lately, and I installed Wireshark (it is a network monitoring tool). You can see everything with this, except encrypted traffic (HTTPS).

    0 讨论(0)
提交回复
热议问题