java http协议如何获取响应内容

通过本站发一个请求到另一个网站,如何获取它的响应信息 并进行筛选自己需要的内容
URLConnection connection = this.url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
Enumeration enumKey = this.request.keys();
while (enumKey.hasMoreElements()) {
String name = (String) enumKey.nextElement();
String value = (String) this.request.get(name);
char ch;
if (enumKey.hasMoreElements())
ch = '&';
else
ch = ' ';
out.print(name + "=" + URLEncoder.encode(value) + ch);
}
-----------------------------------------
Hashtable response = new Hashtable();
String line = "";
while ((line = in.readLine()) != null) {
int i = line.indexOf("=");
if (i != -1)
response.put(line.substring(0, i), line.substring(i + 1));
}
in.close();
这两段代码是同一个方法里的 请问这两段代码什么意思 请大侠尽可能详细说明 感激不尽

用XStream可以将一个java对象序列化成一个xml文件,然后通过http请求将该文件发送过去,然后在另一个网站也用XStream将java对象反序列化回来。反之也是同理。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-10-15
String url = "";
// 获得httpClient
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
// 执行请求获取返回response
HttpResponse response = httpClient.execute(httpPost);
// 获得返回数据
HttpEntity entity = response.getEntity();
// 对返回数据进行操作
...
相似回答