设置CURLOPT_USERPWD时用户名或通过冒号的问题 [英] Problems with username or pass with colon when setting CURLOPT_USERPWD

查看:157
本文介绍了设置CURLOPT_USERPWD时用户名或通过冒号的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正试图在PHP5中使用curl来使用基本身份验证登录网站。

We are trying to use curl in PHP5 to login to a website using basic authentication.

部分代码如下:

<?
...
$uname = "username";
$pass = "p:assword";

curl_setopt($ch,CURLOPT_USERPWD,"$uname:$pass"); 
...
?>

但似乎我们密码中的冒号会导致麻烦。

but it seems the colon in our password is causing trouble.

我们无法更改生产网站的密码,但我们确认该代码在使用字母数字用户名和密码的另一个网站上正常工作。

We are unable to change the password for our production site, but we confirmed the code works fine on another site where an alphanumeric username and password is used.

有没有办法逃避冒号在密码,所以卷曲仍然工作?我们尝试了p \:assword,没有运气。

Is there a way to escape the colon in the password so curl still works? We tried "p\:assword" with no luck.

谢谢。

推荐答案

所以事实证明,这不是一个问题的冒号....
这是认证方案的一个问题。

so it turns out that it wasn't a problem with the colon.... it was a problem with the authentication scheme.

最初我们使用:

curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 

并更改为:

curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

解决了问题。

对另一个服务器有它的缺点 - 服务器工作是在Windows上运行IIS,生产服务器,我们有问题是在linux上运行apache。

Our test against another server had its flaws - the server that worked was running IIS on windows, the production server we were having problems with was running apache on linux.

显然没有使用包含冒号和curl的用户名或密码的问题。

So i repeat: there are apparently no issues with using usernames or passwords that contain colons with curl. this explains why there would be no documentation of this problem.

很抱歉跳过结论,感谢您的帮助。

sorry for jumping to conclusions, and thanks for the help.

这篇关于设置CURLOPT_USERPWD时用户名或通过冒号的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆