我试图从 URL 获取 XML 文件,但没有得到响应,并且代码稍后停止,因为 String xml 为空,你能告诉我有什么问题吗?
public String getXmlFromUrl(String url) {
String xml = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
// I printed the response here but I got nothing !
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
return xml;
} catch (Exception e) {
e.printStackTrace();
}
请具体回答我感谢您的帮助