HttpClient doPost

来源:互联网 发布:r语言读取大数据csv 编辑:程序博客网 时间:2024/05/16 01:13
public static String doPost(String params){String result = null;InputStream is = null;HttpClient httpClient = new HttpClient();PostMethod method = new PostMethod(url);method.setRequestHeader("Content-Type","application/json;charset=UTF-8");method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,charset);  try {RequestEntity requestEntity = new StringRequestEntity(params.toString(),"text/xml","UTF-8");method.setRequestEntity(requestEntity);httpClient.executeMethod(method);// 读取响应is = method.getResponseBodyAsStream();result = IOUtils.toString(is,charset);} catch (Exception e) {e.printStackTrace();} finally {if (method != null) {method.releaseConnection();}if (is != null) {try {is.close();} catch (IOException e1) {e1.printStackTrace();}}}return result;} 

原创粉丝点击