Getting and Setting Cookies in drupal_http_request

Content

Getting and Setting Cookies in drupal_http_request

Posted in:

A Drupal 6 http client request is constructed so:

$http_results = drupal_http_request($url, array(), 'GET', NULL, 3);

Some URLs, however, require that a cookie is passed to each request to ensure that a correct response is issued. First, however, the cookie must be retrieved from an initial request.

$http_results = drupal_http_request($url, array(), 'GET', NULL, 3);
$cookie = $http_results->headers['Set-Cookie'];
$headers = array('Cookie' => $cookie);

Subsequent requests can then include the cookie by specifying the header.

$http_results = drupal_http_request($url, $headers, 'GET', NULL, 3);