CURLOPT_HTTPHEADER 和 CURLOPT_USERPWD 的 PHP cURL 基本身份验证替代方案...?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13654892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP cURL Basic Authentication Alternatives for CURLOPT_HTTPHEADER & CURLOPT_USERPWD...?
提问by Jay S.
Are there any alternatives to using CURLOPT_HTTPHEADER & CURLOPT_USERPWD for supplying Basic Authentication for cURL PHP?
除了使用 CURLOPT_HTTPHEADER 和 CURLOPT_USERPWD 为 cURL PHP 提供基本身份验证之外,还有其他选择吗?
I have a super long password, so CURLOPT_USERPWD wont work as it truncates at 256 characters.
我有一个超长密码,因此 CURLOPT_USERPWD 将无法工作,因为它会截断 256 个字符。
curl_setopt($data, CURLOPT_USERPWD, $username . ":" . $password);
And I would like to stay away from using CURLOPT_HTTPHEADER for security reasons.
出于安全原因,我想远离使用 CURLOPT_HTTPHEADER。
curl_setopt($data, CURLOPT_HTTPHEADER, "Authorization: Basic " . base64_encode($username . ":" . $password));
Any alternatives?
任何替代方案?
回答by drew010
What makes you think CURLOPT_HTTPHEADERis disabled for security reasons?
是什么让您认为CURLOPT_HTTPHEADER出于安全原因被禁用?
It accepts an array rather than a string. Try this instead:
它接受一个数组而不是一个字符串。试试这个:
curl_setopt($data, CURLOPT_HTTPHEADER,
array(
"Authorization: Basic " . base64_encode($username . ":" . $password)
));

