且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法打开流:HTTP请求失败!的HTTP/1.1 400错误请求

更新时间:2021-12-18 00:24:56

一种替代方法是使用cURL(http://php.net/manual/zh-CN/book.curl.php)在之前获取有关请求的更多详细信息印刷品:

One alternative is to use cURL (http://php.net/manual/en/book.curl.php) to get more details about the request before the print:

类似这样的东西也许可以帮助您:

Some like this maybe can help you:

function url_get_contents ($Url) {
    if (!function_exists('curl_init')){ 
        die('CURL is not installed!');
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get the code of request
    curl_close($ch);

    if($httpCode == 400) 
       return 'No donuts for you.';

    if($httpCode == 200) //is ok?
       return $output;


}