CURLOPT_VERBOSE不起作用 [英] CURLOPT_VERBOSE not working
问题描述
Windows 7 x64
PHP 7.2.2 x64
我正在尝试查看简单的请求有效负载,因此我已按 https://docstore.mik.ua/orelly/webprog/pcook/ch11_07.htm
I am trying to view a simple request payload so I have created a PHP file per https://docstore.mik.ua/orelly/webprog/pcook/ch11_07.htm
<?php
$c = curl_init('https://www.google.com');
curl_setopt($c, CURLOPT_VERBOSE, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'monkey=uncle&rhino=aunt');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);
但与示例所示的我可以期望得到的东西一样,我绝对没有输出,
but I get absolutely no output unlike the example which shows that I can expect something like:
* Connected to www.example.com (10.1.1.1)
> POST /submit.php HTTP/1.1
Host: www.example.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Content-Length: 23
Content-Type: application/x-www-form-urlencoded
monkey=uncle&rhino=aunt* Connection #0 left intact
* Closing connection #0
$ page
包含Google 404页面,所以我知道请求成功。
$page
contains a Google 404 page so I know the request is succeeding.
有人知道我是否需要解决其他设置或是否需要明显地做错了什么?
Does anyone know if there are other settings which I need to address or if I am doing something blatantly wrong? In particular, I am interested in the body of the payload.
是的,我知道Google卷曲并不是特别有用;我正在尝试使这个简单的示例正常工作,以便调试出神秘地失败的API交互。
Yes, I am aware that curl'ing Google isn't particularly useful; I am trying to get this simple example to work so that I can debug an API interaction which is mysteriously failing.
每个注释请求的更新
我不能执行 curl -v
,但是 print_r(curl_version());
产生:
I cannot do curl -v
but print_r( curl_version() );
produces:
Array
(
[version_number] => 473344
[age] => 4
[features] => 2428829
[ssl_version_number] => 0
[version] => 7.57.0
[host] => x86_64-pc-win32
[ssl_version] => OpenSSL/1.1.0g
[libz_version] => 1.2.11
[protocols] => Array
(
[0] => dict
[1] => file
[2] => ftp
[3] => ftps
[4] => gopher
[5] => http
[6] => https
[7] => imap
[8] => imaps
[9] => ldap
[10] => pop3
[11] => pop3s
[12] => rtsp
[13] => scp
[14] => sftp
[15] => smb
[16] => smbs
[17] => smtp
[18] => smtps
[19] => telnet
[20] => tftp
)
)
推荐答案
tl; dr
CURLOPT_STDERR
必须设置为特定的值。
设置 curl_setopt($ c,CURLOPT_STDERR,fopen('/ curl.txt','w +')) ;
解决了我的问题。
事实证明, curl_setopt( $ c,CURLOPT_VERBOSE,1);
由于某种原因(我尚未发现)未将输出打印到STDERR。
As it turns out curl_setopt($c, CURLOPT_VERBOSE, 1);
is not printing the output to STDERR for some reason which I have not uncovered. I did not find the output in any of my PHP, Apache, nor Event Viewer logs.
设置 curl_setopt($ c,CURLOPT_STDERR,fopen之后,我没有在任何PHP,Apache或Event Viewer日志中找到输出。
After setting curl_setopt($c, CURLOPT_STDERR, fopen('/curl.txt', 'w+'));
, I was able to see the output in the curl.txt
file.
('/curl.txt','w +')); ,我能够在 curl.txt
文件中看到输出。 / p>
我不确定这是否特定于Windows环境。
I am not sure if this is specific to Windows environments.
这篇关于CURLOPT_VERBOSE不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!