我正在使用 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'
最佳答案
您可以在服务器端尝试这样的方式:
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);
谢谢
关于javascript - C# 中是否有与 JavaScript 的decodeURIComponent() 等效的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56125115/