dou2347 2014-06-21 21:12 采纳率: 0%
浏览 136
已采纳

cURL忽略了选项

The following cURL configuration works fine on my local machine using cURL 7.30.0:

$curl = curl_init();

curl_setopt_array($curl, array(
    // Just showing the noteworthy options here.
    CURLOPT_HTTPHEADER   => array("Content-Type: application/x-www-form-urlencoded")
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
    CURLOPT_COOKIE       => "foo=bar",
));

$response = curl_exec($curl);
curl_close($curl);

Excerpt of the debugging output:

> GET / HTTP/1.0
Host: example.com
Accept: */*
Cookie: foo=bar
Content-Type: application/x-www-form-urlencoded

Now I run the same code on a shared hosting environment with cURL 7.19.7 and get:

> GET / HTTP/1.1
Host: example.com
Accept: */*
Content-Type: application/x-www-form-urlencoded

Basically cURL is working 99% fine, but ignores the forced HTTP version and cookie string. Is the hosting company running a configuration that blocks these features? Is the cURL version they are running too old? What's going on here?

  • 写回答

1条回答 默认 最新

  • duangu4980 2014-06-21 22:34
    关注

    I found it. curl_setopt_array quits processing options as soon as one option fails, I didn't know that. I should've checked the return value to make sure all was well.

    In my case the culprit was option CURLOPT_FOLLOWLOCATION. It probably failed because the hosting provider is using safe mode, which disables the follow 301/302 feature.

    $curl = curl_init();
    
    $check = curl_setopt_array($curl, $options);
    
    if(!$check)
        die("Ye be warned: one of your options did not make it.");
    
    $response = curl_exec($curl);
    curl_close($curl);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!