String requestPath = "http://测试地址?name="+参数;
HttpGet httpGet = new HttpGet(requestPath);
//httpClient实例化
CloseableHttpClient httpClient = HttpClients.createDefault();
// 显示结果
BufferedReader reader = null;
try {
// 设置类型 "application/x-www-form-urlencoded" "application/json"
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
// 执行请求并获取返回
HttpResponse response = httpClient.execute(httpGet);
// System.out.println("Response toString()" + response.toString());
HttpEntity entity1 = response.getEntity();
// 显示结果
reader = new BufferedReader(new InputStreamReader(entity1.getContent(), "UTF-8"));
String line = null;
StringBuffer responseSB = new StringBuffer();
while ((line = reader.readLine()) != null) {
responseSB.append(line);
}
if (!(responseSB.indexOf("哈哈哈,返回了") > -1)){
return false;
}
} catch (Exception e) {
throw new RuntimeException(e);
}finally {
try {
reader.close();
httpClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}