【发布时间】:2015-12-04 21:20:04
【问题描述】:
我使用此代码从 Internet 获取 XML 或 JSON,但它仅适用于 HTTP。所以它不适用于像 Google api 这样的 HTTPS
https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=barack%20obama
错误 405!
private String getXmlFromUrl(String urlString) {
String xml = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(urlString);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity, HTTP.UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
【问题讨论】:
标签: android json androidhttpclient