dongroufan6846 2017-10-30 06:59
浏览 65

PHP cURL与bash命令行中的cuRL有不同的结果

I try to get html result from a site using cURL in PHP, and I got 301 moved permanently, But when I use command line, it working and returning html string reuslt.

This is my Code PHP (result not success)

curl_setopt_array($curl, array(
        CURLOPT_URL => "https://detail.1688.com/offer/535394058500.html?spm=b26110380.sw1688.mof001.302.6YIDM0&v=1",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
        CURLOPT_POSTFIELDS => "a=b",
        CURLOPT_HTTPHEADER => array(
            "cache-control: no-cache",
            "content-type: application/x-www-form-urlencoded",
            "postman-token: b60107e9-4350-e93f-d6cf-d626505687b8"
        ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        echo "cURL Error #:" . $err;
    } else {
        echo $response; // return 301 moved permanent
    }

And this is in CMD (result success)

curl -X GET   'https://detail.1688.com/offer/535394058500.html?spm=b26110380.sw1688.mof001.302.6YIDM0'   -H 'cache-control: no-cache'   -H 'content-type: application/x-www-form-urlencoded'   -H 'postman-token: 2b11da6f-dcde-d527-289c-bfbf8a85d30c'
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向