Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Identify HTTP headers?

Posted on 2010-09-19
8
Medium Priority
?
680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 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