如何使用 Apache Httpclient api 获取 XML 文档响应?
我可以收到回复。如何获取 XML 文档中的响应?我需要使用外部 XML 解析器吗?感谢您的帮助
DefaultHttpClient client = new DefaultHttpClient();
String getUrl = "http://myurl.com";
HttpUriRequest getRequest = new HttpGet(getUrl);
getRequest.setHeader("User-Agent", "xxxx");
HttpResponse response = client.execute(getRequest);
int statusCode = response.getStatusLine().getStatusCode();
log.info("statusCode=" + statusCode);
if (statusCode == 200 ){
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity);
log.info("\n" + content);
}else {
log.warn("failed to response");
}
I can receive the response. How can I get the response in a XML document? do I need to use an external XML parser? thanks for any helps
DefaultHttpClient client = new DefaultHttpClient();
String getUrl = "http://myurl.com";
HttpUriRequest getRequest = new HttpGet(getUrl);
getRequest.setHeader("User-Agent", "xxxx");
HttpResponse response = client.execute(getRequest);
int statusCode = response.getStatusLine().getStatusCode();
log.info("statusCode=" + statusCode);
if (statusCode == 200 ){
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity);
log.info("\n" + content);
}else {
log.warn("failed to response");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了答案,在这里发帖给有同样问题的人
I got my answer, post here for people have the same question