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#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。