[英]HttpUtility.UrlEncode does not encode characters like +
I have a string which is encrypted which looks like this 我有一个加密的字符串,看起来像这样
Pfx32q+xLq4R+VocXy4IC8aQNdmFqdA284THap54Bl4=
On encrypting this string we call the HttpUtility.UrlEncode("Pfx32q+xLq4R+VocXy4IC8aQNdmFqdA284THap54Bl4=")
passing the encrypted string as a parameter this returns a value 加密此字符串后,我们调用HttpUtility.UrlEncode("Pfx32q+xLq4R+VocXy4IC8aQNdmFqdA284THap54Bl4=")
将经过加密的字符串作为参数传递,这将返回一个值
Pfx32q%2BxLq4R%2BVocXy4IC8aQNdmFqdA284THap54Bl4%3D
where in +
is replace with %2 etc and so on on my development system but when the same code is run on a production server the plus does not get encoded instead it remains as + . 在我的开发系统上,其中+
中的替换为%2等,但是在生产服务器上运行相同的代码时,加号未得到编码,而是保留为+。
We are not able to point out what really is causing this . 我们无法指出真正的原因。 Is there a scenario or a case where in on calling of the HttpUtility.UrlEncode
method the characters like + do not get encoded ? 是否存在在调用HttpUtility.UrlEncode
方法时不会像+这样的字符进行编码的情况或情况?
Had the same problem. 有同样的问题。 Converted the encrypted string to Base64 first and then UrlEncoded it. 首先将加密的字符串转换为Base64,然后对其进行UrlEncoded。
string urlOut = HttpUtility.UrlEncode(Base64Encode("Pfx32q+xLq4R+VocXy4IC8aQNdmFqdA284THap54Bl4="));
string urlIn = Base64Decode(HttpUtility.UrlDecode(urlOut));
public static string Base64Encode(string plainText)
{
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
return Convert.ToBase64String(plainTextBytes);
}
public static string Base64Decode(string base64EncodedData)
{
var base64EncodedBytes = Convert.FromBase64String(base64EncodedData);
return Encoding.UTF8.GetString(base64EncodedBytes);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.