1

i am trying to pass the authorization token in my php page. The code i am using is as below:

function getValues(){

    $path='webservice path';

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,$path);

    curl_setopt($ch, CURLOPT_FAILONERROR,1);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic token_no'));

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Access-Control-Allow-Origin: *'));

    $retValue = curl_exec($ch);

    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);

    return $retValue;

}

but i am not able to include the header. Please help me out with this problem.

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
amrita
  • 15
  • 1
  • 1
  • 5

1 Answers1

1

You should only set CURLOPT_HTTPHEADER once, with an array containing all headers.

curl_setopt($ch, CURLOPT_HTTPHEADER,
    array(
         'Authorization: Basic token_no',
         'Content-type: text/xml',
         'Access-Control-Allow-Origin: *'
    ));
Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
  • What isn't working exactly? Remember `token_no` has to be a base64 encoded token. Are you certain that the headers are your issue? You can test that headers are being set by firing off the same request to a local URL, and logging the headers. – Rudi Visser Feb 06 '13 at 10:32