0

I need to send GET Request method with the below headers . I am getting the following capture from HTTP live headers


***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
----------------------------**------------------------------*

I am using the following program . It is not working . Please let me know where I am going wrong.

  <?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);
  }?>
1
  • GET is not a header .... Commented Apr 9, 2010 at 11:43

2 Answers 2

1

you don't want to send all of those parameters through, the only ones you need are

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==

the other headers come from the server's reply, and you won't need to set the GET /HTTP/1.1 as it's implicit in the request anyway.

Sign up to request clarification or add additional context in comments.

4 Comments

Probably, the only header the OP actually has to send is the Authorization.
possibly, and user-agent too if necessary. depends what s/he's trying to test
But I am not able get the html page back . How do I do that ?
are you getting anything back? i can't test with your server since it's down but using essentially the same code with google.com in it, seems to work. also you'll want to leave out the Accept-Encoding: gzip,deflate line unless you're prepared to ungzip stuff.
0

You need to set CURLOPT_HEADER => TRUE to include the header in the output.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.