first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

PHP cURL: building headers for a HTTP Request

This is an example for building headers for a cURL call in PHP:

$ch = curl_init();
$user_agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';

…

$headers = array();

$headers[] = "POST " . $postPath . " HTTP/1.1";
$headers[] = "Host: " . $postHost;
$headers[] = "Content-type: text/xml";
$headers[] = "Content-length: " . mb_strlen($content, "UTF-8");
$headers[] = "Connection: close";

…

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

The complete code sample is here:

http://www.tanguay.info/web/codeExample.php?id=993
mod date: 2008-07-03T20:01:21.000Z