views:

197

answers:

2

Hi there, here's my problem, I am receiving a string from a soap Webservice which seems to contain UTF8 encoded %c3%89. This string is a URL i have to reach to get a picture that contains a part of the URL in it.

My problem is that the server generating the picture doesn't recognize the %c3%89 encoding and thus doesn't create the right . When replaced with it's normal representation (i.e É) the server is generating the picture correctly.

My question is: How can i replace the encoded character in the string?

Ps: I don't have access to the server side

here's my code

URL aURL = new URL(URLDecoder.decode(url)); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(bis);

Thanks a lot :)

Hush

+2  A: 

You need to pass the character encoding as 2nd argument to URLDecoder#decode(), otherwise it will use the platform default character encoding.

System.out.println(URLDecoder.decode("%c3%89", "ISO-8859-1")); // Ã?
System.out.println(URLDecoder.decode("%c3%89", "UTF-8")); // É
BalusC
Thank you for your answer yet it did not solve my problem. I ll try to make myself clear.'URL aURL = new URL(URLDecoder.decode(url)); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); 'At this point the url used by UrlConnection object is understandable for the server (When i copy paste it on any browser it returns the right picture). The problem is passing through InputStream which apparently doesn't send the same request as a browser... I 'm kind of lost there...
Hush
What do you mean with "passing through InputStream"? Sorry, after all your question is pretty confusing and ambiguous. Fact is, somewhere the wrong encoding is been used to decode the character.
BalusC
A: 

I just realized that the URL was perfectly understood by the website when using earlier version of android (lets say before 2.2) I start to wonder what has changed in the urlconnection framework since that version... anyway i will try to pass through this problem by hosting the required picture on the webservice rather than returning the url.

Thank you

Hush