繁体   English   中英

php的CURLOPT_USERPWD做了什么

[英]What does php's CURLOPT_USERPWD do

我想知道CURLOPT_USERPWD实际上对请求的url,标头或数据做了什么。 它是Authorization: Basic <base64 of user:pass> INSTEAD Authorization: Basic <base64 of user:pass>还是它在这边工作?

是修改网址吗?:

username:password@someurl.com

我看到了一些像这样的代码,所以我想知道,因为看起来我在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);

谢谢

是修改网址吗?:

username:password@someurl.com

不,网址仍然相同。 你可以查看

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);

正在做同样的事情所以没有必要一起使用它们(尽管它不会破坏),使用一个它会工作正常。

暂无
暂无

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

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