【发布时间】:2014-10-24 19:52:34
【问题描述】:
我有一个链接http://www.example.com/Movies.aspx?movname=Raja Natwarlal
这是我的代码
file_get_contents($link, false, $context);
它给了我这个错误
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
我也试过这个代码
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get the code of request
curl_close($ch);
它给了我 $httpCode=400
【问题讨论】:
-
首先可能值得尝试正确地 http 转义 url 中的空白,其次可能是服务器拒绝了请求并且确实发送了错误 400。
-
我也试过 urlencode() 但没有运气
-
在整个 url 上使用
urlencode()没有任何意义。这不是我的建议。 -
试试这些变体:
http://www.example.com/Movies.aspx?movname=Raja+Natwarlal和http://www.example.com/Movies.aspx?movname=Raja%20Natwarlal... -
不客气 :-) 我转发了这个建议作为答案。
标签: php http file-get-contents