简体   繁体   English

php的CURLOPT_USERPWD做了什么

[英]What does php's CURLOPT_USERPWD do

I was wondering what CURLOPT_USERPWD is actually doing to the url, header or data of a request. 我想知道CURLOPT_USERPWD实际上对请求的url,标头或数据做了什么。 Is it INSTEAD OF the Authorization: Basic <base64 of user:pass> or does it work along side this? 它是Authorization: Basic <base64 of user:pass> INSTEAD Authorization: Basic <base64 of user:pass>还是它在这边工作?

Is it modifying the url to this?: 是修改网址吗?:

username:password@someurl.com

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): 我看到了一些像这样的代码,所以我想知道,因为看起来我在NodeJS等效请求中请求它的url只是一个Authorization标头(我有理论服务器坏了,忽略了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);

Thanks 谢谢

Is it modifying the url to this?: 是修改网址吗?:

username:password@someurl.com

No, the url still the same. 不,网址仍然相同。 You can check with 你可以查看

curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

This 这个

$encodedAuth = base64_encode(self::$pfAdapterUser.":".self::$pfAdapterPasswd);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic ".$encodedAuth));

And this 还有这个

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. 正在做同样的事情所以没有必要一起使用它们(尽管它不会破坏),使用一个它会工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM