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
Solved

How to Identify HTTP headers?

Posted on 2010-09-19
8
676 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 125 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure 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 125 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

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). #…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

839 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