2010-04-09 2 views
0

아래 헤더와 함께 GET Request 메소드를 보내야합니다. 나는 HTTP에서 다음 캡처를 얻고 라이브 헤더CURL을 사용하여 헤더로 HTTP get 메소드를 보내는 방법


***http://172.20.22.26/ 

GET/HTTP/1.1 
Host: 172.20.22.26 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Authorization: Basic bWl0aHVuOm1pdGh1bg== 

HTTP/1.x 200 OK 
Date: Thu, 01 Jan 2009 00:29:20 GMT 
Server: HTTPsrv 
Connection: Keep-Alive 
Keep-Alive: timeout=30, max=100 
Transfer-Encoding: chunked 
Content-Type: text/html 
----------------------------**------------------------------* 

나는 다음과 같은 프로그램을 사용하고 있습니다. 그것은 작동하지 않습니다 . 내가 어디로 잘못 가고 있는지 알려주세요.

<?php 

$credentials = "mithun:mithun"; 

$url = "http://172.20.22.26"; 
$headers = array(
"GET /HTTP/1.1", 
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1", 
"Content-type: text/xml;charset=\"utf-8\"", 
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",   "Accept-Language: en-us,en;q=0.5", 
"Accept-Encoding: gzip,deflate", 
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", 
"Keep-Alive: 300",  
"Connection: keep-alive", 
"Authorization: Basic " . base64_encode($credentials)); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    //curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);    

$data = curl_exec($ch); 
if (curl_errno($ch)) { 
    print "Error: " . curl_error($ch); 
    } 
else { 
// Show me the result 
var_dump($data); 
curl_close($ch); 
    }?> 
+0

GET은 헤더가 아닙니다 .... – RageZ

답변

1

당신은 당신이 필요로하는 유일한 사람이

Host: 172.20.22.26 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Authorization: Basic bWl0aHVuOm1pdGh1bg== 

다른 헤더

서버의 응답에서 올 수 있습니다 통해 그 모든 매개 변수를 보낼 싶지 않아, 당신은 설정할 필요가 없습니다 어쨌든 요청에 ​​함축되어 있으므로 GET /HTTP/1.1.

+0

OP가 실제로 보내야하는 유일한 헤더는 Authorization입니다. 가능하다면 –

+0

및 user-agent도 필요합니다. 어떤/그가 테스트하려고 시도에 따라 달라집니다 – oedo

+0

하지만 html 페이지를 다시 얻을 수 없습니다. 어떻게해야합니까? – Vidya

0

출력에 헤더를 포함하려면 CURLOPT_HEADER => TRUE로 설정해야합니다.

관련 문제