@Test public void testForm() throws Exception { Map<String,String> param=Maps.newHashMap(); param.put("token", "12345"); String result = HttpUtils.form("http: assertEquals(expected,result); }
public static String form(String url, Map<String,String> sendData) throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); config(httpPost); Set<Map.Entry<String,String>> dataSet=sendData.entrySet(); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); for(Entry<String,String> entry:dataSet){ formParams.add(new BasicNameValuePair(entry.getKey(),entry.getValue())); } UrlEncodedFormEntity uefEntity= new UrlEncodedFormEntity(formParams, Consts.UTF_8.name()); httpPost.setEntity(uefEntity); HttpResponse response = httpClient.execute(httpPost); return HttpResToString(response, Consts.UTF_8.name()); } finally { close(httpClient); } }
HttpUtils { public static String form(String url, Map<String,String> sendData) throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); config(httpPost); Set<Map.Entry<String,String>> dataSet=sendData.entrySet(); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); for(Entry<String,String> entry:dataSet){ formParams.add(new BasicNameValuePair(entry.getKey(),entry.getValue())); } UrlEncodedFormEntity uefEntity= new UrlEncodedFormEntity(formParams, Consts.UTF_8.name()); httpPost.setEntity(uefEntity); HttpResponse response = httpClient.execute(httpPost); return HttpResToString(response, Consts.UTF_8.name()); } finally { close(httpClient); } } }
HttpUtils { public static String form(String url, Map<String,String> sendData) throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); config(httpPost); Set<Map.Entry<String,String>> dataSet=sendData.entrySet(); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); for(Entry<String,String> entry:dataSet){ formParams.add(new BasicNameValuePair(entry.getKey(),entry.getValue())); } UrlEncodedFormEntity uefEntity= new UrlEncodedFormEntity(formParams, Consts.UTF_8.name()); httpPost.setEntity(uefEntity); HttpResponse response = httpClient.execute(httpPost); return HttpResToString(response, Consts.UTF_8.name()); } finally { close(httpClient); } }  }
HttpUtils { public static String form(String url, Map<String,String> sendData) throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); config(httpPost); Set<Map.Entry<String,String>> dataSet=sendData.entrySet(); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); for(Entry<String,String> entry:dataSet){ formParams.add(new BasicNameValuePair(entry.getKey(),entry.getValue())); } UrlEncodedFormEntity uefEntity= new UrlEncodedFormEntity(formParams, Consts.UTF_8.name()); httpPost.setEntity(uefEntity); HttpResponse response = httpClient.execute(httpPost); return HttpResToString(response, Consts.UTF_8.name()); } finally { close(httpClient); } }  static String get(String url); static String delete(String url); static String post(String url, String sendData,Map<String,String> headers); static String put(String url, String sendData,Map<String,String> headers); static String get(String url, String decodeCharset); static String delete(String url, String decodeCharset); static String post(String url, String sendData, Map<String,String> headers,String encodeCharset,String decodeCharset); static String put(String url, String sendData,Map<String,String> headers,String encodeCharset,String decodeCharset); static String form(String url, Map<String,String> sendData); }
HttpUtils { public static String form(String url, Map<String,String> sendData) throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); config(httpPost); Set<Map.Entry<String,String>> dataSet=sendData.entrySet(); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); for(Entry<String,String> entry:dataSet){ formParams.add(new BasicNameValuePair(entry.getKey(),entry.getValue())); } UrlEncodedFormEntity uefEntity= new UrlEncodedFormEntity(formParams, Consts.UTF_8.name()); httpPost.setEntity(uefEntity); HttpResponse response = httpClient.execute(httpPost); return HttpResToString(response, Consts.UTF_8.name()); } finally { close(httpClient); } }  static String get(String url); static String delete(String url); static String post(String url, String sendData,Map<String,String> headers); static String put(String url, String sendData,Map<String,String> headers); static String get(String url, String decodeCharset); static String delete(String url, String decodeCharset); static String post(String url, String sendData, Map<String,String> headers,String encodeCharset,String decodeCharset); static String put(String url, String sendData,Map<String,String> headers,String encodeCharset,String decodeCharset); static String form(String url, Map<String,String> sendData);  }