【问题标题】:Curl failing with HTTP error 500卷曲失败并出现 HTTP 错误 500
【发布时间】:2015-09-16 22:41:49
【问题描述】:

这是我从caller.php发出的代码

$data["names"] = $names;
$data["sizes"] = $sizes;

$destination =  $url.'/script.php';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $destination);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);

curl_setopt($ch, CURLOPT_POST, true);

$pf = $data;

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($pf));
curl_exec($ch);
$feedback = curl_getinfo($ch);
debug($feedback,"feedback curl");
curl_close($ch);

这是服务器结构

root
     /folder/caller.php
     /script.php

我无法决定让自己得出一个可能是错误的结论......我试图以本地主机的身份发出 curl 请求,但我什至做不到。我只得到500,仅此而已。有人可以帮我想想可能会发生什么吗?

【问题讨论】:

  • 500 是服务器端错误,可能你的script.php 工作不正常。
  • $url 定义了吗? (只是为了彻底) - “回显” $destination 会导致有效的 URL 吗?

标签: php curl


【解决方案1】:

尝试添加用户代理和引荐来源标头。有时需要访问。

 curl_setopt(CURLOPT_REFERER, 'http://google.com');
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");

【讨论】:

    【解决方案2】:
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
    

    出于测试目的,删除该行并查看是否得到 500。我刚刚遇到了一个问题,即当将无效标头传递给 curl 时引发了 err 500。修复标题,为我解决了问题。

    【讨论】:

      猜你喜欢
      • 2022-08-04
      • 2010-09-15
      • 2023-04-04
      • 2013-08-13
      • 1970-01-01
      • 2015-05-18
      • 2017-06-04
      • 2017-04-12
      • 2021-05-18
      相关资源
      最近更新 更多