zoukankan      html  css  js  c++  java
  • file_get_contents HTTP request failed! Internal Server Error

    使用file_get_contents报错

    Severity: Warning
    Message: file_get_contents(http://geetest.com:8000/select?gid=bf59a3fe652ece81dfb179219ce5b46e&date=2013-08-09) [function.file-get-contents]: failed to open stream: HTTP request failed! Internal Server Error

    遇到这种情况不要慌,我们只要将php默认的user_agent改成Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)进来模拟浏览器即可。

    修改方法:

    PHP伪造user_agent

       ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)');

    伪造自后还是不行

      $context = stream_context_create(array('http'=>array('ignore_errors'=>true)));

      $nos = file_get_contents($url, FALSE, $context);

    完整栗子:

    ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)');
    $context = stream_context_create(array('http'=>array('ignore_errors'=>true)));
    file_get_contents($url, FALSE, $context);

     

  • 相关阅读:
    1. 两数之和
    RabbitMQ主题交换机
    RabbitMQ路由
    RabbitMQ发布订阅
    RabbitMQ简介和安装
    55. 跳跃游戏
    63. 不同路径 II
    62. 不同路径
    6. Z 字形变换
    sql注入攻击与防御第一章(笔记)
  • 原文地址:https://www.cnblogs.com/54sen/p/6732145.html
Copyright © 2011-2022 走看看