dongrong8972 2017-09-30 10:22
浏览 266
已采纳

加载网站服务器端返回403错误

I was trying to get RSS info from a website the other day, but when I tried to load it using PHP it returned a 403 error.

This was my PHP code:

<?php
    $rss = file_get_contents('https://hypixel.net/forums/-/index.rss');
    echo $rss;
?>

And the error I got was:

failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

I must say that loading it regularly from a browser works just fine, but when I try loading it using PHP or any other server-side method it won't work.

  • 写回答

1条回答 默认 最新

  • duande1986 2017-09-30 10:28
    关注

    Some people don't like servers accessing their stuff. They provide a service intended for human consumers, and not bots. Therefore they may include code that checks whether you are in fact a human using a web browser, which your naïve PHP script is failing to provide. Therefore, the third-party is returning a 403 Forbidden error, indicating that it is forbidden for your program to access it.

    There are ways around this, of course, depending on how it's implemented. The most obvious thing to do is send a User-Agent header pretending to be a browser. But servers may do more clever checks than this, and it's questionably moral.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊