【发布时间】:2015-11-17 14:36:45
【问题描述】:
我使用支持 Apache HTTP 客户端从 url 获取 xml。
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, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
Google 宣布从 Android 6.0 开始取消对 Apache HTTP 客户端的支持,并改用 HttpURLConnection 类。 最后,我想使用 HttpURLConnection 从 url 获取 xml,但我不知道!有人可以帮助我:)
【问题讨论】:
标签: android xml httpurlconnection