Ric*_*ick 82 php curl header request libcurl
我正在构建一个Curl Web自动化应用程序,并且遇到一些问题但是没有得到我的POST动作的预期结果,我在查明如何显示我发送的完整POST请求(带标题)时遇到了一些问题,我一直在搜索这个,但所有出现的是响应标题,实际上我也想要这些,但也请求,我在谷歌上找到的任何帖子似乎都没有提到..
我知道我可以使用类似的东西显示curl请求的结果(原谅我,如果我的语法关闭,我已经用我的ide和代码关闭我的虚拟机来引用
$result = curl($curl_exect) ;
Run Code Online (Sandbox Code Playgroud)
无论如何,我非常感谢有关如何查看完整标题的任何建议,谢谢
Jos*_*ust 166
这就是你所需要的:
curl_setopt($curlHandle, CURLINFO_HEADER_OUT, true); // enable tracking
... // do curl request
$headerSent = curl_getinfo($curlHandle, CURLINFO_HEADER_OUT ); // request headers
Run Code Online (Sandbox Code Playgroud)
Rob*_*itt 70
您可以通过执行以下操作查看有关转移的信息:
curl_setopt($curl_exect, CURLINFO_HEADER_OUT, true);
Run Code Online (Sandbox Code Playgroud)
在请求之前,和
$information = curl_getinfo($curl_exect);
Run Code Online (Sandbox Code Playgroud)
请求后
你也可以使用CURLOPT_HEADER你的curl_setopt
curl_setopt($curl_exect, CURLOPT_HEADER, true);
$httpcode = curl_getinfo($c, CURLINFO_HTTP_CODE);
if($httpcode == 200) {
return true;
}
return false;
Run Code Online (Sandbox Code Playgroud)
这些只是使用标题的一些方法.
小智 10
您可以使用以下命令将curl发送的所有标题保存到文件中:
$f = fopen('request.txt', 'w');
curl_setopt($ch,CURLOPT_VERBOSE,true);
curl_setopt($ch,CURLOPT_STDERR ,$f);
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法让自己请求标题:
// 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);
Run Code Online (Sandbox Code Playgroud)
喜欢写如何提出要求