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);
  • 相关阅读:
    Cookie和Session
    Csrf
    Django中间件
    ORM操作
    Django框架简介
    Django之模型的高级用法
    Linux基础(二)之命令
    01 numpy库(一)
    Django之缓存配置
    20 Django REST Framework 更改PUT/PATCH/DELETE的传参字段,默认为pk
  • 原文地址:https://www.cnblogs.com/yixiu868/p/11867266.html
Copyright © 2011-2022 走看看