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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题