.NET UrlEn code - 小写问题, [英] .net UrlEncode - lowercase problem
问题描述
我工作的一个数据传输要求我在UrlEn codeD的形式发送数据的网关。但是,.NET的UrlEn code创建小写字母标记,它打破了转移(Java的创建大写)。
I'm working on a data transfer for a gateway which requires me to send data in UrlEncoded form. However, .net's UrlEncode creates lowercase tags, and it breaks the transfer (Java creates uppercase).
任何想法我怎么能强迫.NET做大写URL编码?
Any thoughts how can I force .net to do uppercase UrlEncoding?
UPDATE1:
.NET出来:
dltz7UK2pzzdCWJ6QOvWXyvnIJwihPdmAioZ%2fENVuAlDQGRNCp1F
VS Java的:
vs Java's:
dltz7UK2pzzdCWJ6QOvWXyvnIJwihPdmAioZ%2FENVuAlDQGRNCp1F
(这是一个base64d 3DES字符串,我需要保持它的情况下)。
(it is a base64d 3DES string, i need to maintain it's case).
推荐答案
我想你坚持什么C#给你,并得到错误提示的另一端执行不力UrlDe code函数。
I think you're stuck with what C# gives you, and getting errors suggests a poorly implemented UrlDecode function on the other end.
随着中说,你应该只需要通过字符串循环和大写只有两个字符如下%符号。这将让您的base64数据完好无损,而按摩EN codeD字符转换成合适的格式为:
With that said, you should just need to loop through the string and uppercase only the two characters following a % sign. That'll keep your base64 data intact while massaging the encoded characters into the right format:
public static string UpperCaseUrlEncode(string s)
{
char[] temp = HttpUtility.UrlEncode(s).ToCharArray();
for (int i = 0; i < temp.Length - 2; i++)
{
if (temp[i] == '%')
{
temp[i + 1] = char.ToUpper(temp[i + 1]);
temp[i + 2] = char.ToUpper(temp[i + 2]);
}
}
return new string(temp);
}
这篇关于.NET UrlEn code - 小写问题,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!