user2227359
user2227359

Reputation: 317

HTTP Request header

I am familiar with displaying items from and XML feed using PHP, but an API I have just started working on requires me to include the HTTP Request header...

   Feed-Auth => myPassword

How do I include a HTTP Request Header?

Upvotes: 1

Views: 185

Answers (2)

raidenace
raidenace

Reputation: 12826

header("Feed-Auth:".$myPassword);

If you are hitting the API using something like curl or soap, they have their own mechanisms for setting headers.

Curl:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Feed-Auth:'.$myPassword));

SOAP

  $header = array('Feed-Auth'=>$myPassword);
  $soapHeader = new SoapHeader('NAMESPACE','Header',$header,false);
  $client->__setSoapHeaders($oapHeader);

Upvotes: 1

Ja͢ck
Ja͢ck

Reputation: 173522

You would have to load the document in another way and use simplexml_load_string():

$body = file_get_contents($url, false, stream_context_create(array(
    'http' => array(
        'header' => 'Feed-Auth: myPassword',
    ),
)));

$doc = simplexml_load_string($body);

Upvotes: 0

Related Questions