file_get_contents() failed to open stream:

前端 未结 2 764
我寻月下人不归
我寻月下人不归 2020-12-05 16:03

I\'m trying to use file_get_contents() to grab a twitter feed, however I\'m getting the following warning:

failed to open stream: HTTP request          


        
相关标签:
2条回答
  • 2020-12-05 16:08

    Most probably, your server have mod_security enabled. Add the below lines in your .htaccess after any existing rules and then try to see the issue is still there, after that addition.

    <IfModule mod_security.c>
     SecFilterScanPost
    </IfModule>
    
    0 讨论(0)
  • 2020-12-05 16:26

    You should use the PHP cURL extension if it's available, as it's many times faster, more powerful, and easier to debug. Here is an example that does the same thing you were trying:

    function curl($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $data = curl_exec($ch);
        curl_close($ch);
    
        return $data;
    }
    
    $feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name=google&count=6';
    $tweets = curl($feed);
    
    0 讨论(0)
提交回复
热议问题