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);

     

  • 相关阅读:
    Vue Router详细教程
    Vue CLI使用
    百度点选识别,单字90+
    CPU毫秒级 | 极验点选识别
    Linux内核之进程管理
    Linux内核之基本概念
    MySQL InnoDB技术内幕:内存管理、事务和锁
    ZooKeeper简介
    分布式一致性协议之ZAB
    图解HTTP读书笔记
  • 原文地址:https://www.cnblogs.com/54sen/p/6732145.html
Copyright © 2011-2022 走看看