Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net UrlEncode - lowercase problem

Tags:

.net

urlencode

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).

like image 744
balint Avatar asked May 27 '09 21:05

balint


People also ask

Are double quotes allowed in URL?

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 .

What is UrlEncode in C#?

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.

What does %2C in URL mean?

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.


1 Answers

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); } 
like image 75
Kevin Avatar answered Sep 20 '22 05:09

Kevin