[英]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.