转义基本身份验证 URL 中的用户名字符 [英] Escaping username characters in basic auth URLs

查看:30
本文介绍了转义基本身份验证 URL 中的用户名字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用http基本认证时,可以在URL中传入用户名,例如

When using http basic authentication, the username can be passed in the URL, e.g.

http://david@foo.com/path/

但现在假设用户名是一个电子邮件地址,例如david@company.com.这样做显然是模棱两可的:

But now suppose the username is an email address, e.g. david@company.com. Doing this is clearly ambiguous:

http://david@company.com@foo.com/path/

有没有办法转义用户名中的@ 字符?我尝试了标准 URL 编码:

Is there a way to escape the @ character in the username? I tried standard URL encoding:

http://david%40company.com@foo.com/path/

但这并没有做到.

推荐答案

根据 RFC 3986, section 3.2.1,它需要进行百分比编码:

According to RFC 3986, section 3.2.1, it needs to be percent encoded:

  userinfo    = *( unreserved / pct-encoded / sub-delims / ":" )

看起来像

http://david%40company.com@foo.com/path/

是对的.你想在哪里阅读它?也许您需要手动解码该值?

Is right. Where are you trying to read it? Maybe you need to manually decode the value?

这篇关于转义基本身份验证 URL 中的用户名字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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