Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP, curl, and raw headers

Tags:

php

curl

When using the PHP curl functions, is there anyway to see the exact raw headers that curl is sending to the server?

like image 998
Alan Storm Avatar asked Dec 01 '09 21:12

Alan Storm


People also ask

How do I get response headers in cURL?

We can use curl -v or curl -verbose to display the request headers and response headers in the cURL command. The > lines are request headers .

How does PHP handle cURL response?

Just use the below piece of code to get the response from restful web service url, I use social mention url. Oldie bug a goodie... +1 for using curl_setopt_array(). So much cleaner than calling curl_setopt() over and over.

Can I use cURL in PHP?

cURL is a PHP extension that allows you to use the URL syntax to receive and submit data. cURL makes it simple to connect between various websites and domains.

How can I get response header in PHP?

There is a simple solution built into cURL if you are only interested in the response headers and not the content of the body. By setting the CURLOPT_HEADER and CURLOPT_NOBODY options to true, the result of curl_exec() will only contain the headers.


1 Answers

You can use curl_getinfo:

Before the call

curl_setopt($ch, CURLINFO_HEADER_OUT, true); 

After

$headers = curl_getinfo($ch, CURLINFO_HEADER_OUT); 
like image 198
Greg Avatar answered Oct 02 '22 15:10

Greg