1

我正在尝试在我的 php 页面中传递授权令牌。我正在使用的代码如下:

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;

}

但我无法包含标题。请帮我解决这个问题。

4

1 回答 1

1

你应该只设置CURLOPT_HTTPHEADER一次,一个包含所有标题的数组。

curl_setopt($ch, CURLOPT_HTTPHEADER,
    array(
         'Authorization: Basic token_no',
         'Content-type: text/xml',
         'Access-Control-Allow-Origin: *'
    ));
于 2013-02-06T10:14:58.147 回答