【问题标题】:php cURL password contains @php cURL 密码包含@
【发布时间】:2012-06-24 10:51:26
【问题描述】:

我正在尝试将 cURL 与代理设置一起使用,在我将密码更改为使用 @ 符号之前它运行良好。

这是我定义代理的方式:

curl_setopt($curl, CURLOPT_PROXY, "http://test:test@test@10.20.5.15:90");

有没有办法使用带有@ 符号的代理通行证(在我的情况下密码是test@test)并让cURL 工作?

【问题讨论】:

标签: php curl


【解决方案1】:

您也可以使用 %40 代替“@”:

curl_setopt($curl, CURLOPT_PROXY, "http://test:test%40test@10.20.5.15:90"); 但最好像@lix 所说的那样使用CURLOPT_USERPWD ...

【讨论】:

  • 密码中包含:怎么办?
【解决方案2】:

您可能想尝试使用cURL set_opts 方法来设置您的用户名和密码。

CURLOPT_USERPWD
格式为“[username]:[password]”的用户名和密码以使用 用于连接。

一个例子看起来像这样 -

curl_setopt($curl, CURLOPT_USERPWD, "test:test@test"); 

【讨论】:

  • 如果密码中包含: 怎么办?
  • @beppe9000 - 您可以尝试使用: 的url 编码版本,即%3A。我用这个网站来转换它urlencoder.org.
  • 这与其他答案的解决方案相同
  • 好吧 php 有一个内置的 urlencode 函数,所以我会使用它,就像这样:curl_setopt($curl, CURLOPT_USERPWD, urlencode($user).':'.urlencode($password).'@'.$host.':'.$port);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-01
  • 2020-11-06
  • 2016-03-18
  • 1970-01-01
  • 2012-03-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多