java http协议如何获取响应内容
通过本站发一个请求到另一个网站,如何获取它的响应信息并进行筛选自己需要的内容URLConnectionconnection=this.url.openConnection...
通过本站发一个请求到另一个网站,如何获取它的响应信息 并进行筛选自己需要的内容
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();
这两段代码是同一个方法里的 请问这两段代码什么意思 请大侠尽可能详细说明 感激不尽 展开
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();
这两段代码是同一个方法里的 请问这两段代码什么意思 请大侠尽可能详细说明 感激不尽 展开
2个回答
展开全部
String url = "";
// 获得httpClient
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
// 执行请求获取返回response
HttpResponse response = httpClient.execute(httpPost);
// 获得返回数据
HttpEntity entity = response.getEntity();
// 对返回数据进行操作
...
// 获得httpClient
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
// 执行请求获取返回response
HttpResponse response = httpClient.execute(httpPost);
// 获得返回数据
HttpEntity entity = response.getEntity();
// 对返回数据进行操作
...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询