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);
  • 相关阅读:
    WebApi-JSON序列化循环引用
    Android ImageSwitcher
    Android Gallery
    理解URI
    WebApi入门
    URL的组成
    Http协议
    python __new__和__init__的区别
    11.6
    win7 32位用pyinstaller打包Python和相关html文件 成exe
  • 原文地址:https://www.cnblogs.com/yixiu868/p/11867266.html
Copyright © 2011-2022 走看看