donglinxi1467 2018-04-04 19:13
浏览 678
已采纳

CURLOPT_VERBOSE不起作用

Windows 7 x64
PHP 7.2.2 x64

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 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.

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.

Updates, per comment request

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
        )

)
  • 写回答

1条回答 默认 最新

  • doucigua0449 2018-04-05 11:37
    关注

    tl;dr

    CURLOPT_STDERR must be set to something specific.

    Setting curl_setopt($c, CURLOPT_STDERR, fopen('/curl.txt', 'w+')); fixed my issue.


    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.

    After setting curl_setopt($c, CURLOPT_STDERR, fopen('/curl.txt', 'w+'));, I was able to see the output in the curl.txt file.

    I am not sure if this is specific to Windows environments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大