0

私の urls 配列には 100 個の URL が含まれており、そのようなもののために設計された API から情報を取得しています。とにかく、URLの50%が返されるように

400 Bad Request


Your browser sent a request that this server could not understand.
GET /player/euw/Wolves Deficio/ingame HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Host: api.captainteemo.com
Accept: */*

URL は 100% 正しいので、ブラウザにコピーすると情報が取得されます。

これが私のコードです:

function get_data($urls) {
    // spoofing FireFox 2.0
    $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

    $ch = curl_init();

    // set user agent
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
    if(is_array($urls)) {
        $output = array();
        foreach($urls as $url) {
            // set the rest of your cURL options here
            curl_setopt($ch, CURLOPT_URL, $url); 
            //return the transfer as a string 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
            // $output contains the output string 
            array_push($output, curl_exec($ch));
        }
    }
    else {
        // set the rest of your cURL options here
        curl_setopt($ch, CURLOPT_URL, $urls); 
        //return the transfer as a string 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        // $output contains the output string 
        $output = curl_exec($ch);

    }
    // close curl resource to free up system resources 
    curl_close($ch);    

    return $output;
}
4

2 に答える 2

0

問題は、本物のユーザー エージェントを使用する代わりにユーザー エージェントをスプーフィングしたことと、" " を "+" に置き換えなかったことです。

于 2013-04-12T10:40:19.173 に答える