Ignacio Soler Garcia
Ignacio Soler Garcia

Reputation: 21855

How to find out the right encoding of a webservice respose?

I'm developing a Windows pone 8 application that is calling a third party web service. That service is returning some text with the following response:

HTTP/1.1 200 OK
Date: xxxxxxxxxx
Server: Apache/xxxxxxxxx
X-Powered-By: PHP/5xxxxxxxxxx
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html

I'm getting the information from the web service using a WebClient and the UploadStringAsync method. On the response I'm getting characters like á and others ... How can I fix this? I've tried changing the WebClient encoding (without knowing too much what I'm really doing) without success.

EDIT:

I'm reveiving a JSON response which contains text like this one (in several languages apart from english):

"description":"Podcast del programa de Radio El D& iacute;a. Aqu& iacute; encontrar& aacute;s d& iacute;a a d& iacute;a"

[I have added spaces between the & and the other characters because otherwise SO shows the correct text]

Upvotes: 1

Views: 779

Answers (1)

Joe Carr
Joe Carr

Reputation: 313

The accented special characters are being returned from the webservice because ISO-8859-1 is the default character set in most browsers, and you can just send the resulting strings to a browser for the correct decoding.

But, since you're not sending it to a browser, you can also decode them yourself with :

string json = "Podcast del programa de Radio El Día. Aquí encontrarás día a día";
string decoded = HttpUtility.HtmlDecode(json);

From this SO link you'll be directed here for a version of HttpUtility which you can run on Windows Phone.

Upvotes: 1

Related Questions