Api包Symfony集合授权头
在symfony2中,我使用这个bundle库()发出API请求。 这是执行此操作的主要功能:Api包Symfony集合授权头,symfony,oauth,authorization,Symfony,Oauth,Authorization,在symfony2中,我使用这个bundle库()发出API请求。 这是执行此操作的主要功能: $output = $this->get('api_caller')->call(new HttpPostJson($url, $parameters)); 我想为oAuth 2设置一个身份验证头 谢谢我大约一个月前用过那个图书馆。我通过定制类HttpPostJson就解决了这个问题 你应该这样做: in Lsw\ApiCallerBundle\Call public function
$output = $this->get('api_caller')->call(new HttpPostJson($url, $parameters));
我想为oAuth 2设置一个身份验证头
谢谢我大约一个月前用过那个图书馆。我通过定制类HttpPostJson就解决了这个问题 你应该这样做:
in Lsw\ApiCallerBundle\Call
public function makeRequest($curl, $options, $authorization)
{
$curl->setopt(CURLOPT_URL, $this->url);
$curl->setopt(CURLOPT_POST, 1);
$curl->setopt(CURLOPT_POSTFIELDS, $this->requestData);
$curl->setopt(CURLOPT_HTTPHEADER, array(
'Authorization: ' . $authorization
));
$curl->setoptArray($options);
$this->responseData = $curl->exec();
}
我刚才补充说
$curl->setopt(CURLOPT_HTTPHEADER, array(
'Authorization: ' . $authorization
));
在每个需要授权的API调用中。您不必编写代码,因为库已经准备好接收任何curl选项 将HttpHeader像关联数组一样传递,如下例所示:
//it's a fake test
$url = 'http://www.example.com';
$data = array();
$returnAssociativeArray = true;
//add curl options
$options = array(
'userpwd' => 'demo:privateKey'
'httpheader' => array('Content-type' => 'application/json')
);
$json = $this->container->get('api_caller')->call(
new HttpPostJson(
$url,
$data,
$returnAssociativeArray,
$options
)
);
httppostjson()中的第二个参数是LeaseWeb/LswApiCallerBundle/Call/CurlCall.php的对象,其构造函数是公共函数uu构造($url、$requestObject、$asAssociativeArray=false){$this->url=$url;$this->requestObject=$requestObject;$this->asAssociativeArray=$asAssociativeArray;$this->generateRequestData();}@abbiya谢谢!但是我应该把授权放在哪里:$Authorization?在我的示例中