您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

file_get_contents抛出400错误的请求错误PHP

file_get_contents抛出400错误的请求错误PHP

您可能想尝试使用curl而不是file_get_contents来检索数据。curl对错误处理有更好的支持

// make request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.twitter.com/1/statuses/user_timeline/User.json"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch);

// convert response
$output = json_decode($output);

// handle error; error output
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {

  var_dump($output);
}

curl_close($ch);

这可以使您更好地了解为什么收到此错误一个常见的错误是达到服务器上的速率限制。

php 2022/1/1 18:13:56 有600人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶