php 的 CURLOPT_USERPWD 有什么作用 [英] What does php's CURLOPT_USERPWD do
问题描述
我想知道 CURLOPT_USERPWD 实际上对请求的 url、标头或数据.它是代替 Authorization: Basic
还是与此一起工作?
I was wondering what CURLOPT_USERPWD is actually doing to the url, header or data of a request. Is it INSTEAD OF the Authorization: Basic <base64 of user:pass>
or does it work along side this?
是否将url修改为这个?:
Is it modifying the url to this?:
用户名:password@someurl.com
我看到了一些这样的代码,所以我想知道,因为似乎如果我在 NodeJS 等效请求中请求该 url,它不能仅使用 Authorization 标头(我有一个理论,服务器已损坏并忽略了 Auth 标头并在网址中使用用户名:密码):
I saw some code like this so I am wondering, as it seems if I request that url in a NodeJS equivalent request it is not working with just an Authorization header (I have a theory the server is broken and ignoring the Auth header and using the username:password in the 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);
谢谢
推荐答案
是否将url修改为这个?:
Is it modifying the url to this?:
用户名:password@someurl.com
不,网址还是一样.您可以查看
No, the url still the same. You can check with
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);
正在做同样的事情,所以没有必要一起使用它们(虽然它不会坏),使用一个就可以了.
are doing the same thing so there's no need to use them together (although it won't break), use one and it will work fine.
这篇关于php 的 CURLOPT_USERPWD 有什么作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!