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).
Any thoughts how can I force .net to do uppercase UrlEncoding?
update1:
.net out:
dltz7UK2pzzdCWJ6QOvWXyvnIJwihPdmAioZ%2fENVuAlDQGRNCp1F
vs Java's:
dltz7UK2pzzdCWJ6QOvWXyvnIJwihPdmAioZ%2FENVuAlDQGRNCp1F
(it is a base64d 3DES string, i need to maintain it's case).
Show activity on this post. I know that the double quote character is not allowed in the url and it is encoded as %22 and this is done with utf-8 encoding .
UrlEncode(String, Encoding)Encodes a URL string using the specified encoding object. public: static System::String ^ UrlEncode(System::String ^ str, System::Text::Encoding ^ e); public: static System::String ^ UrlEncode(System::String ^ s, System::Text::Encoding ^ Enc); C# Copy.
The %2C means , comma in URL. when you add the String "abc,defg" in the url as parameter then that comma in the string which is abc , defg is changed to abc%2Cdefg . There is no need to worry about it.
I think you're stuck with what C# gives you, and getting errors suggests a poorly implemented UrlDecode function on the other end.
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With