在C#中是否有与JavaScript的encodeURIComponent()等效的东西?

时间:2019-05-14 07:31:58

标签: javascript c# asp.net angular ionic-framework

我正在使用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'

1 个答案:

答案 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);

谢谢