我有git代理配置为'http.proxy = http:// userId:pwd @ 123 @ipaddress:port'但是在克隆远程项目时,我收到错误
Cloning into git...
error: Couldn't resolve proxy '123@ipaddress' while accessing http://git.kernel.org/pub/scm/git/git.git/info/refs
fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)
如何逃避密码中的'@'字符?
请注意:我无法更改密码.
Joh*_*don 133
如果您在代理网址中传递密码,我会尝试使用@符号的URL编码值:
http.proxy=http://userId:pwd%40123@ipaddress:port
Run Code Online (Sandbox Code Playgroud)
Von*_*onC 54
注(2013年11月)
对url进行编码(尤其是密码中的任何特殊字符)是正确的解决方案.
在.netrc
下文提到的是仅用于远程回购网址,而不是使用的代理服务器来解析所述远程回购网址.
对于所述编码,请参阅" 百分比编码 ":
百分比编码(也称为URL 编码)是在某些情况下在统一资源标识符(URI)中编码信息的机制.虽然它被称为URL编码,但实际上它更普遍地用在主统一资源标识符(URI)集中,其包括统一资源定位符(URL)和统一资源名称(URN).因此,它还用于准备application/x-www-form-urlencoded 媒体类型的数据,这通常用于在HTTP请求中提交HTML 表单数据.
百分比编码后的保留字符:
! # $ & ' ( ) * + , / : ; = ? @ [ ]
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
Run Code Online (Sandbox Code Playgroud)
原始答案(2011年5月)
两条评论:
拥有使用http(而不是https)访问的服务器的密码是......很奇怪.在客户端和服务器之间的通信期间,密码未加密;
您可以使用以下内容在您的设置中设置.netrc
(或_netrc
用于Windows)$HOME
machine ipaddress:port login userId password pwd@
Git b在场景后面使用的卷曲会处理编码很好,@
或者没有@
.
Rav*_*ekh 13
你必须进行百分比编码| 对特殊字符进行编码。例如,而不是这个:
http://user:Pa@s@http-gateway.domain.org:80
Run Code Online (Sandbox Code Playgroud)
你写这个:
http://user:Pa%40s@http-gateway.domain.org:80
Run Code Online (Sandbox Code Playgroud)
因此@
被替换为%40
.
小智 5
URL编码任何不寻常的字符。
@ character is %40
Run Code Online (Sandbox Code Playgroud)
在我的git配置文件中,我已经编码了“仅”用户名,例如:
@ character is %40
Run Code Online (Sandbox Code Playgroud)
例如,您的密码存储在环境变量中GIT_PASSWORD
,用户名 - GIT_USERNAME
,然后:
git clone http://${GIT_USERNAME}:$(echo -n $GIT_PASSWORD | hexdump -v -e '"x" 1/1 "%02X"' | tr x %)@repository.git
Run Code Online (Sandbox Code Playgroud)
说明: echo -n $GIT_PASSWORD | hexdump -v -e '"x" 1/1 "%02X"' | tr x %
$GIT_PASSWORD
<-hello
hello
<-x68x65x6Cx6Cx6F
x68x65x6Cx6Cx6F
<-%68%65%6C%6C%6F