繁体   English   中英

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

[英]Is there any equivalent to JavaScript's decodeURIComponent() in C#?

我正在使用Angular 7开发Ionic应用程序。不幸的是,当用户使用' + '登录密码时遇到问题。 在Angular post请求中,“ + ”号被空格代替。

我在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);

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM