zoukankan      html  css  js  c++  java
  • HttpClient常用方法总结

    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);
  • 相关阅读:
    第一周C语言作业
    C语言I博客园作业08
    C语言I博客作业07
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言II博客作业04
    C语言II博客作业03
    C语言II博客作业02
    C语言II博客作业01
  • 原文地址:https://www.cnblogs.com/yixiu868/p/11867266.html
Copyright © 2011-2022 走看看