【问题标题】:How to get the http method used in curl_php()如何获取 curl_php() 中使用的 http 方法
【发布时间】:2019-07-17 06:33:39
【问题描述】:

如何获取 curl_php 连接中使用的 HTTP 方法(如 GET、POST、DELETE)?在curl_getinfo 中不可用。 连接代码是

$options = array(
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER         => false,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_MAXREDIRS      => 10,
            CURLOPT_ENCODING       => "",
            CURLOPT_AUTOREFERER    => true,
            CURLOPT_CONNECTTIMEOUT => 120,
            CURLOPT_TIMEOUT        => 120,
    );
    $response = curl_init($url);
    curl_setopt_array($response, $options);
    $content  = curl_exec($response);
    $options_debug = curl_getinfo($response);
    curl_close($response);

【问题讨论】:

  • 没有办法做到这一点。但是由于您必须明确配置它,您可以编写一个跟踪它的包装器。

标签: php curl libcurl php-curl


【解决方案1】:

默认情况下,cURL 方法始终是 GET,除非您以不同方式指定它。此外,如果您使用 -d 或 --data 调用 cURL,则请求将是 POST。

POST request override default GET when using -d parameter.

更多信息在这里:cURL info

BR

【讨论】:

    猜你喜欢
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多