通过PHP cURL创建一个包含HTTP基本授权头的POST

时间:2017-04-07 19:24:52

标签: php curl

指令

发布内容类型为x-www-form-urlencoded到以下网址的帖子请求:https://api/openid/token/revokeToken 包括HTTP基本授权标头,由用户名:密码

的base64编码组成

即使无法识别令牌,该呼叫也应发出200 OK响应。使用响应正文将错误传达给客户。

尝试

我试过

$OPENID_TOKEN_REVOKE_URL = 'https://api/openid/token/revokeToken';
$auth_code = base64_encode('username:password'); //dXNlcm5hbWU6cGFzc3dvcmQ=

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$OPENID_TOKEN_REVOKE_URL);
curl_setopt($ch, CURLOPT_USERPWD, $auth_code);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));


// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

dd($server_output);

我得到了

"<html><head><title></title></head><body>15058752898584540867</body></html>"

我也试试

$headers = array(
      "Content-Type: application/x-www-form-urlencoded",
      "Authorization: Basic " . $auth_code
  );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$OPENID_TOKEN_REVOKE_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);

dd($server_output);

我得到与上面相同的结果

"<html><head><title></title></head><body>15058752898584540867</body></html>"

根据我的iDP指示

“使用响应正文将错误传达给客户”

这是否意味着我从cURL返回的错误?

0 个答案:

没有答案