GET запрос cURL

f.x

Новичок
GET запрос cURL

Подскажите, плиз в чем может быть проблема:
PHP:
<?php
$headers = array(
            "GET /images/test.gif HTTP/1.0",
            "Accept: */*",
            "Referer: http://www.test.ru/",
            "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
            "Host: www.test.ru",
            "Connection: Keep-Alive"
        );
       
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'test.ru');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $data = curl_exec($ch); 
        if (curl_errno($ch)) {
            echo "Error: " . curl_error($ch);
        } else {
            echo "$data";
            curl_close($ch);
        }


?>
Смотрю запрос:
PHP:
GET / HTTP/1.1
Accept: */*
Referer: http://www.test.ru/
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Host: www.test.ru
Connection: Keep-Alive
т.е. всегда запрашивается / , не зависимо от строки GET в массиве заголовков.
 

kode

never knows best
Re: GET запрос cURL

Автор оригинала: f.x
Подскажите, плиз в чем может быть проблема:
PHP:
<?php
$headers = array(
            "GET /images/test.gif HTTP/1.0",
            "Accept: */*",
            "Referer: [url]http://www.test.ru/[/url]",
            "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
            "Host: [url]www.test.ru[/url]",
            "Connection: Keep-Alive"
        );
       
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'test.ru');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $data = curl_exec($ch); 
        if (curl_errno($ch)) {
            echo "Error: " . curl_error($ch);
        } else {
            echo "$data";
            curl_close($ch);
        }


?>
Смотрю запрос:
PHP:
GET / HTTP/1.1
Accept: */*
Referer: [url]http://www.test.ru/[/url]
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Host: [url]www.test.ru[/url]
Connection: Keep-Alive
т.е. всегда запрашивается / , не зависимо от строки GET в массиве заголовков.
PHP:
<?php
$headers = array(
"Accept: */*",
"Referer: http://www.test.ru/",
"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Host: www.test.ru",
"Connection: Keep-Alive");

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,'/images/test.gif');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$data = curl_exec($ch); 
if (curl_errno($ch)) {
    echo "Error: " . curl_error($ch);
} else {
    echo "$data";
}

curl_close($ch);

?>
 
Сверху