在 URL 中传递用户名和密码无效

Passing user and password in URL doesn't work

我有一些像这样的 URL : X.XXX.XXX.XXX:10080

我试着在这个 url 中添加用户和密码,如下所示:http://OLM:OLM794$@X.XXX.XXX.XXX:10080

用户 = OLM

Psw = OLM794$

而且它不起作用

另外当我 运行 : curl http://OLM:OLM794$@X.XXX.XXX.XXX:10080 它显示我 :

curl: (6) Could not resolve host:OLM:OLM794X.XXX.XXX.XXX,它删除 $@ 和端口 :10080

当我尝试时:curl -u OLM X.XXX.XXX.XXX:10080 然后我输入密码,它有效,我能够连接到该服务器。

我需要用这样的用户名和密码来调用我的 url:

http://OLM:OLM794$@X.XXX.XXX.XXX:10080

但是不行。

我阅读了这个解决方案:Using cURL with a username and password?但我还没有找到解决方案

你知道为什么吗?

似乎 curl 解析并重建了 URL,删除了它认为非法的字符。对我来说,同样的命令给出了不同的错误。可能是你的 curl 版本与我的不同。

$ curl -v http://OLM:OLM794$@127.0.0.1:10000
* Rebuilt URL to: http://OLM:OLM794127.0.0.1:10000/
* Port number ended with 'O'
* Closing connection -1
curl: (3) Port number ended with 'O'

解决方案非常简单,只需 url-转义 $ 符号:%24:

$ curl http://OLM:OLM794%24@127.0.0.1:10000

例如,根据RFC1738, the dollar-sign was allowed as an unreserved character and could be directly used, but this old RFC has since been updated many times. RFC3986,不再将其作为非保留字符提及。这意味着 $ 符号具有特殊含义,应该在任何 URL 中编码,如果它不提供给定的功能。