【发布时间】:2011-07-09 20:52:11
【问题描述】:
我遇到了 PHP 的 file_get_contents 命令的问题。
$url = "http://api.rememberthemilk.com/services/rest/".$format.$auth_token.$filter."&api_sig=".$md5.$apikey.$method;
$content = file_get_contents($url);
$array = json_decode($content, true);
$taskname = $array['rsp']['tasks']['list']['taskseries']['name'];
$duedate = $array['rsp']['tasks']['list']['taskseries']['task']['due'];
($format, $auth_token, $filter, $md5, $apikey, $method 已经在脚本中定义了)
当我尝试运行此代码时,会返回此错误:
[function.file-get-contents]:打开流失败:HTTP 请求失败! HTTP/1.1 400 第 101 行的错误请求
第 101 行 = $content, = file_get_contents($url);
如何解决这个问题?谢谢!!!
【问题讨论】:
-
file_get_contents中没有什么需要修复的。您尝试读取的 URL 不正确。 -
请显示您尝试阅读的完整网址(当然没有您的身份验证令牌)
-
也有可能是请求无效(参数错误,你好像串联有点多),或者PHP user_agent被阻塞了。
-
您可能需要检查 allow_url_fopen 的值。此函数的 php 文档中还可以找到有用的信息作为注释。
-
这是网址:
http://api.rememberthemilk.com/services/rest/?format=json&auth_token=AUTH_TOKEN&filter=dueWithin:"3 days of today"&api_sig=API_SIG&api_key=API_KEY&method=rtm.tasks.getList(我替换了实际的 auth_token、api_sig 和 api_key)
标签: php httprequest file-get-contents