我正在使用Angular 7开发Ionic应用程序。不幸的是,在用户使用“ + ”登录密码时遇到问题。在Angular发布请求中,“ + ”符号替换为空格。
我在stackoverflow中找到了一些解决方案,并使用了JavaScript的encodeURIComponent()来对密码进行编码。它将“ +”符号转换为“%2B”。
但是,我的API中找不到任何解码器来解码“ %2B ”到“ + ”符号。注意,我的服务器端是用ASP.NET(C#)编写的。或者,有没有办法发送带有' + '符号的密码而不转换为'%2B '
'content-type': 'application/x-www-form-urlencoded'
示例密码 :'abc+123'
无 encodeURIComponent()
:'abc 123'
使用 encodeURIComponent()
:'abc%2B123'
答案 0 :(得分:2)
您可以在服务器端以这种方式尝试:
string encodedValue="abc%2B123";
string decodedvalue= Uri.UnescapeDataString(encodedValue);
Console.WriteLine(decodedvalue);
-- or
string encodedValue1=HttpUtility.HtmlEncode("abc+123");
string decodedValue1 = HttpUtility.HtmlDecode(encodedValue1);
Console.WriteLine(decodedValue1);
谢谢