1.POST方式
public static void main(String[] args) throws UnsupportedEncodingException, IOException{
Map<String, Object> map = new HashMap<String, Object>();
map.put("ceshi", "1");
Map<String, String> list=new HashMap<String, String>();
list.put("date",token);
String RepairListForApp = httpPost("http://",list, map);
System.out.println(RepairListForApp);
}
public static String httpPost(String url,Map<String, String> header,Map map){
// 返回body
String body = null;
// 获取连接客户端工具
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse httpResponse=null;
// 2、创建一个HttpPost请求
HttpPost post = new HttpPost(url);
// 5、设置header信息
/**header中通用属性*/
post.setHeader("Accept","*/*");
post.setHeader("Accept-Encoding","gzip, deflate");
post.setHeader("Cache-Control","no-cache");
post.setHeader("Connection", "keep-alive");
post.setHeader("Content-Type", "application/json;charset=UTF-8");
/**业务参数*/
if (header!=null) {
Iterator<Map.Entry<String, String>> it =header.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String, String> entry = it.next();
System.out.println(entry.getKey()+":"+entry.getValue());
post.setHeader(entry.getKey(), entry.getValue());
}
}
// 设置参数
if (map != null) {
try {
StringEntity entity1=new StringEntity(JSON.toJSONString(map),