2

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 Answers 2

4

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")); // É
Sign up to request clarification or add additional context in comments.

3 Comments

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...
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 you just saved me from committing sucide :D
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.