Php curl POST请求的客户端错误无效

Php curl POST请求的客户端错误无效,php,curl,Php,Curl,我在尝试从oauth端点获取访问令牌时遇到问题 我用下面的方法提出了一个curlpost请求 $username='Joe'; $password='Doe@#!' $auth='Basic y245y3blegf4atp2zwludgzmmmvwbgd5anu1y2n6agztnmz3oxdlnmj='; $headers=[ “授权”=>$auth, “内容类型”=>“应用程序/x-www-form-urlencoded”, ]; $form_params=[ “用户名”=>$usernam

我在尝试从oauth端点获取访问令牌时遇到问题

我用下面的方法提出了一个curlpost请求

$username='Joe';
$password='Doe@#!'
$auth='Basic y245y3blegf4atp2zwludgzmmmvwbgd5anu1y2n6agztnmz3oxdlnmj=';
$headers=[
“授权”=>$auth,
“内容类型”=>“应用程序/x-www-form-urlencoded”,
];
$form_params=[
“用户名”=>$username,
“密码”=>$password,
“授权类型”=>“密码”,
'范围'=>'自动'
];
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,”https://oauth.wildapricot.org/auth/token");
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($form_params));
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$response=curl\u exec($ch);
卷曲关闭($ch);
返回$response;
但是我不断得到一个
无效客户端
错误(
$auth
变量包含在客户端中,并且用base 64进行了秘密编码)。 我尝试过对postfields进行编码,但没有帮助。我已经硬编码了
$auth
变量,以防
base64\u encode
函数弄乱它(我以前用该函数生成过),但它没有改变任何东西

我已经检查过端点实际上是与邮递员一起工作的,事实上是这样

对可能出现的问题有什么想法吗

编辑:我刚刚在代码中添加了一些调试行,这就是我得到的(如果有帮助的话)

*正在尝试34.226.77.200:443。。。
*TCP_节点集
*已连接到oauth.wildapricot.org(34.226.77.200)端口443(#0)
*阿尔卑斯山,提供h2
*ALPN,提供http/1.1
*密码选择:全部:!出口:!出口40:!出口56:!阿努尔:!低:!RC4:@强度
*已成功设置证书验证位置:
*CAfile:/usr/local/etc/openssl/cert.pem
CApath:/usr/local/etc/openssl/certs
*使用TLSv1.2/ECDHE-RSA-AES128-GCM-SHA256的SSL连接
*ALPN,服务器不同意协议
*服务器证书:
*主题:C=CA;postalCode=M5J 2L7;ST=安大略省;L=多伦多;街道=前街西144号;O=野生杏公司。;OU=PremiumSSL通配符;CN=*.wildapricot.org
*开始日期:2018年9月20日00:00:00 GMT
*到期日期:11月17日23:59:59格林威治标准时间2020
*主题名称:主机“oauth.wildapricot.org”匹配证书“*.wildapricot.org”
*发行人:C=GB;ST=大曼彻斯特;L=萨尔福德;O=科摩多CA有限公司;CN=COMODO RSA组织验证安全服务器CA
*SSL证书验证正常。
>POST/auth/token HTTP/1.1
主持人:oauth.wildapricot.org
接受:*/*
内容长度:76
内容类型:application/x-www-form-urlencoded
*上传已完全发送:76个字节中有76个
*将捆绑包标记为不支持多用途
这一行告诉我们您的身份验证有问题:

WWW-Authenticate:Basic realm=“需要认证”

Curl为HTTP基本身份验证提供了一种更简单的方法。尝试删除
Authorization
标题并改为设置
CURLOPT_USERPWD
选项:


curl_setopt($ch,CURLOPT_USERPWD,$username.:“$password)

尝试使用另一种HTTP基本身份验证方法:完全有效!如果你愿意,你可以把它写下来,作为将来有同样问题的人的答案。太好了!很高兴听到这个消息。已完成:)
*   Trying 34.226.77.200:443...
* TCP_NODELAY set
* Connected to oauth.wildapricot.org (34.226.77.200) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /usr/local/etc/openssl/cert.pem
  CApath: /usr/local/etc/openssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=CA; postalCode=M5J 2L7; ST=Ontario; L=Toronto; street=144 Front Street West; O=Wild Apricot Inc.; OU=PremiumSSL Wildcard; CN=*.wildapricot.org
*  start date: Sep 20 00:00:00 2018 GMT
*  expire date: Nov 17 23:59:59 2020 GMT
*  subjectAltName: host "oauth.wildapricot.org" matched cert's "*.wildapricot.org"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Organization Validation Secure Server CA
*  SSL certificate verify ok.
> POST /auth/token HTTP/1.1
Host: oauth.wildapricot.org
Accept: */*
Content-Length: 76
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 76 out of 76 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Length: 68
< Content-Type: application/json; charset=utf-8
< Expires: -1
< WWW-Authenticate: Basic realm="authentication required"
< X-Powered-By: ASP.NET
< Access-Control-Allow-Origin: *
< Date: Fri, 15 Nov 2019 12:29:30 GMT
< Connection: close
< X-Backend-Server: lap1wue1b-62e2
< X-LB-Server: llblue1b-5471
< 
* Closing connection 0