/** * 发送HTTP请求 * * @param url * @param propsMap * 发送的参数 */ public static String httpSend(String url, MappropsMap) { String responseMsg = ""; HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(url);// POST请求 // 参数设置 Set keySet = propsMap.keySet(); NameValuePair[] postData = new NameValuePair[keySet.size()]; int index = 0; for (String key : keySet) { postData[index++] = new NameValuePair(key, propsMap.get(key).toString()); } postMethod.addParameters(postData); try { httpClient.executeMethod(postMethod);// 发送请求 // 读取内容 byte[] responseBody = postMethod.getResponseBody(); // 处理返回的内容 responseMsg = new String(responseBody); } catch (HttpException e) { e.printStackTrace(); Logger.getLogger(PaymentAction.class).error(e.getMessage()); } catch (IOException e) { e.printStackTrace(); Logger.getLogger(PaymentAction.class).error(e.getMessage()); } finally { postMethod.releaseConnection();// 关闭连接 } return responseMsg; }