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

查看:535
本文介绍了转义基本身份验证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 第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天全站免登陆