I'm trying to parse an online xml file but there seems to be something wrong with the way the data is shown on the website I'm trying to retrieve it from.
This is my method to get the string of a website back;
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
When I debug the code the xml
string for the link I've requested returns this;
The link in the picture above is the link, so I saved the data from that website into my own xml file and uploaded it here and if I used this link it would work fine but using the 'cloud' link in my picture it returns those weird characters, anyone know why?
在此行添加“UTF-8”参数:
xml = EntityUtils.toString(httpEntity, "UTF-8");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.