【发布时间】:2014-07-11 15:25:07
【问题描述】:
我想知道CURLOPT_USERPWD 实际上对请求的 url、标头或数据做了什么。它是代替Authorization: Basic <base64 of user:pass> 还是与它一起工作?
是不是把url改成这个了?:
username:password@someurl.com
我看到了一些这样的代码,所以我想知道,因为如果我在 NodeJS 等效请求中请求该 url,它似乎不能仅使用 Authorization 标头(我有一个理论是服务器已损坏并忽略 Auth 标头并在 URL 中使用用户名:密码):
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$encodedAuth = base64_encode(self::$pfAdapterUser.":".self::$pfAdapterPasswd);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authentication : Basic ".$encodedAuth));
curl_setopt($ch, CURLOPT_USERPWD, self::$pfAdapterUser.":".self::$pfAdapterPasswd);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
谢谢
【问题讨论】:
-
设置wireshark并检查一下。
标签: php curl basic-authentication