How to send HTTP get method with headers using CURL
Posted
by mithunmo
on Stack Overflow
See other posts from Stack Overflow
or by mithunmo
Published on 2010-04-09T11:40:37Z
Indexed on
2010/04/09
11:43 UTC
Read the original article
Hit count: 430
Hello ,
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);
}?>
© Stack Overflow or respective owner