1、HttpPost发送表单请求

1  String url = "";
2  HttpPost httpPost = new HttpPost(url);
3  List<NameValuePair> params = new ArrayList<>();
4  params.add(new BasicNameValuePair("username", "root"));
5  params.add(new BasicNameValuePair("password", "123456"));
6  UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(params, "utf-8");
7  httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
8  httpPost.setEntity(uefEntity);

 2、HttpPost发送json参数请求

1 String url = "";
2 String json = ""; // 请求参数,json格式
3 HttpPost httpPost = new HttpPost(url);
4 StringEntity entity = new StringEntity(json, "UTF-8");
5 httpPost.setHeader("Content-Type", "application/json");
6 httpPost.setEntity(entity);

 3、HttpPost发送xml参数请求

1 String url = "";
2 String xml = ""; // 请求参数,xml格式
3 HttpPost httpPost = new HttpPost(url);
4 StringEntity entity = new StringEntity(xml, "UTF-8");
5 httpPost.setHeader("Content-Type", "text/xml");
6 httpPost.setEntity(entity);

 

相关文章:

  • 2021-10-16
  • 2021-10-16
  • 2019-10-12
  • 2021-11-04
  • 2021-09-28
  • 2021-09-10
  • 2022-01-25
猜你喜欢
  • 2021-12-17
  • 2022-12-23
  • 2020-06-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-11-22
相关资源
相似解决方案