HttpClient使用post方式模拟表单提交数据

转载 2020-09-21 11:29 Java 29
java 复制代码
//组装url
String url = "http://192.168.0.105:8080/";
// 创建httpClient
CloseableHttpClient httpClient = HttpClients.createDefault();
// 创建post请求方式实例
HttpPost httpPost = new HttpPost(url);
List<NameValuePair>list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("tableName",tableName));
list.add(new BasicNameValuePair("fileName",fileName));
list.add(new BasicNameValuePair("path",path));
HttpEntity entity = new UrlEncodedFormEntity(list);//模拟form进行表单提交
httpPost.setEntity(entity);                               //banding内容
HttpResponse response = httpClient.execute(httpPost); //连接服务器
HttpEntity entit =  response.getEntity(); //获取内容
return EntityUtils.toString(entit, "utf-8");
点赞
收藏
关注
转发
本文作者: Veddy
版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议进行许可。转载请署名作者且注明文章出处。
文章目录