Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to Identify HTTP headers?

Posted on 2010-09-19
8
Medium Priority
?
682 Views
Last Modified: 2012-05-10
Hello:

I am using PHP / CURL to open a remote URL.

All works fine. However, I want to identify what HEADERS are sent when I am requesting a particular URL using PHP/CURL? Also, i would like to capture the HEADERS which are received back with the URL.

Any examples?
0
Comment
Question by:nainil
8 Comments
 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 500 total points
ID: 33713864
Hello nainil,

Following are some links that might help you. Please check them out.

http://php.net/manual/en/ref.curl.php

http://it.toolbox.com/wiki/index.php/Use_curl_from_PHP_-_processing_response_headers

http://www.bigresource.com/Tracker/Track-php-1OSr9l3e/

Hopefully it will help you.

Thanks.
0
 

Author Comment

by:nainil
ID: 33716241
amar_bardoliwala: Thanks.

However, I was looking for something different. May be I did not frame my question correctly.

I am not setting any HEADERS before requesting a page through CURL. So, apparently, some default headers are being sent and returned.

My task is to identify WHAT headers are sent while requesting a URL through CURL.

Hope it helps!
0
 

Author Comment

by:nainil
ID: 33716589
Also that information would linclude Useragent etc which is being sent.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Expert Comment

by:Coryf88
ID: 33731364

$ch = curl_init('http://www.google.com');

curl_setopt_array($ch, array(
	CURLOPT_RETURNTRANSFER	=> TRUE,
	CURLOPT_HEADER			=> TRUE,
	CURLINFO_HEADER_OUT		=> TRUE,
));

list($response_headers, $response_body) = explode("\r\n\r\n", curl_exec($ch), 2);
$info = curl_getinfo($ch);
curl_close($ch);

var_dump($info['request_header'], $response_headers, $response_body);

Open in new window

0
 
LVL 15

Assisted Solution

by:samri
samri earned 500 total points
ID: 33755455
Here is the plain HTTP GET Request from CURL (WinXP)
Curl version:
curl 7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
Protocols: dict file ftp ftps http https imap imaps ldap pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS Largefile NTLM SSL SSPI libz

Request:
No.     Time        Source                Destination           Protocol SrcPrt DstPrt Info                                                            DelTme
     16 5.720232    192.168.1.101         64.233.181.105        HTTP     21790  80     GET / HTTP/1.1                                                  0.002500

Frame 16 (189 bytes on wire, 189 bytes captured)
Ethernet II, Src: Intel_28:20:d4 (00:19:d2:28:20:d4), Dst: HewlettP_0d:df:ba (00:11:85:0d:df:ba)
Internet Protocol, Src: 192.168.1.101 (192.168.1.101), Dst: 64.233.181.105 (64.233.181.105)
Transmission Control Protocol, Src Port: 21790 (21790), Dst Port: http (80), Seq: 1, Ack: 1, Len: 135
Hypertext Transfer Protocol
    GET / HTTP/1.1\r\n
     User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3\r\n
    Host: www.google.com\r\n
    Accept: */*\r\n
    \r\n

In brief, the plain get would send the header : User-Agent:, Host:, Accept:



Hope this helps.
0
 

Author Comment

by:nainil
ID: 33802629
samri: can you please advise how you grabbed this HTTP GET request from Curl on Windows?

Was it through PHP or some sniffer?
0
 

Author Comment

by:nainil
ID: 34213026
Closing the question.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question