zoukankan      html  css  js  c++  java
  • java 模拟 post request payload

    post 请求

    先贴代码

    public String sendCPICPostRequest(String requestUrl, String cookStr, String licenceNo, String referer, String host) {

    String payload = "{"meta":{},"redata":{"ecarvo":{"plateNo":"" + licenceNo + "","carVIN":"","plateColor":"1"}}}";



    StringBuffer jsonString;
    try {
    URL url = new URL(requestUrl);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Accept", "application/json");
    connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    connection.setRequestProperty("Cookie", cookStr);
    connection.setRequestProperty("Host", host);
    connection.setRequestProperty("Referer", referer);

    OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
    writer.write(payload);
    writer.close();
    BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    jsonString = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {
    jsonString.append(line);
    }
    br.close();
    connection.disconnect();
    } catch (Exception e) {
    throw new RuntimeException(e.getMessage());
    }
    return jsonString.toString();
    }

      

      

  • 相关阅读:
    python实现RSA加密解密方法
    信息安全-2:python之hill密码算法[原创]
    信息安全-4:公钥密码体制之背包算法[原创]
    python之import子目录文件
    python之路径导入
    python之局部变量引用赋值前的结果
    python之socket-ssh实例
    python之面向对象与构造函数
    git搜索--grep
    git日志--log
  • 原文地址:https://www.cnblogs.com/proli/p/8630590.html
Copyright © 2011-2022 走看看