我想知道 CURLOPT_USERPWD 实际上对请求的 url、标头或数据做了什么。它是代替
Authorization: Basic <base64 of user:pass>
还是与此一起工作?
是否将url修改为这样?:
username:[email protected]
我看到了一些这样的代码,所以我想知道,因为似乎如果我在 NodeJS 等效请求中请求该 url,它不能仅使用授权标头(我有一个理论,服务器已损坏并忽略 Auth 标头并使用网址中的用户名:密码):
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);
谢谢
是否将url修改为这样?:
username:[email protected]
不,网址仍然相同。您可以通过
查看curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
这个
$encodedAuth = base64_encode(self::$pfAdapterUser.":".self::$pfAdapterPasswd);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic ".$encodedAuth));
还有这个
curl_setopt($ch, CURLOPT_USERPWD, self::$pfAdapterUser.":".self::$pfAdapterPasswd);
正在做同样的事情,所以没有必要一起使用它们(虽然它不会损坏),使用一个就可以正常工作。