Android Question .NET back end - strange behavior of StringUtils

hatzisn

Well-Known Member
Licensed User
Longtime User
Hi everyone,

I am debugging a .NET back end with Fiddler. I am trying to upload to a SOAP web service (.asmx) a byte array from the Android app. What I do is turning the byte array to a Base64 string and sending this string UrlEncoded with string utils. On the web service side I UnescapeDataString the Base64 string and recreate the byte array with Convert.FromBase64String. This direction works perfect as I save the byte array to a binary file and I am able to open the binary file with no problem and check the incredients with a hex editor which are correct. Now when I try to do the opposite which is to load the binary incredients of the file to a byte array in .NET back end, convert this to a Base64 string (Convert.ToBase64String), return this Base64 string with EscapeDataString (UrlEncode) in Android app and with StringUtils UrlDecode this string and convert this Base64 string again to a byte array with string utils, the byte array is got completely different. This is very annoying and completely strange because the Base64 string returned in the Android side is exactly the same with the string sent from the .NET back end. I coppied the incredients of the Base64 strings in both sides and I compared them and they were same. I also checked the byte array in .NET back end which is loaded from the file and it is correct. Any ideas on what am I supposed to do now?


Thanks in advance,
Nikolaos Hatzistelios


P.S. My previous post was deleted with Reason: Very rude to bump your question after 2 hours. So I am reposting it. Was that done automatically?
 

MarkusR

Well-Known Member
Licensed User
Longtime User
UrlEncoded is used typically for http get request because a url row have chars with special meanings.
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
I used the UrlEncode because generally in case the data you send to a web service contains the character "&" it throws an exception (the web service). So as a measure of precaution I always use the UrlEncode. The fact is that when I send the Base64 string in the webservice (UrlEncoded) the web service UrlDecodes it and process it correctly getting the correct byte array. The opposite way is darned wrong. I url encode in the web service (Uri.EscapeDataString) the Base64 string and send it back. It is received correctly (at least it seams to be) but the output from StringUtils is completely different.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Base64 does not use &, so need to urlencoding
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
Thanks for the response. I will do it A.S.A.P.
 
Upvote 0
Top