zoukankan      html  css  js  c++  java
  • 5.6团队冲刺09

    今天封装了一下工具类,快完成了

    public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding)
            throws Exception {
        URL url = new URL(generalUrl);
        // 打开和URL之间的连接
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        // 设置通用的请求属性
        connection.setRequestProperty("Content-Type", contentType);
        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setUseCaches(false);
        connection.setDoOutput(true);
        connection.setDoInput(true);
    
        // 得到请求的输出流对象
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(params.getBytes(encoding));
        out.flush();
        out.close();
    
        // 建立实际的连接
        connection.connect();
        // 获取所有响应头字段
        Map<String, List<String>> headers = connection.getHeaderFields();
        // 遍历所有的响应头字段
        for (String key : headers.keySet()) {
            System.err.println(key + "--->" + headers.get(key));
        }
        // 定义 BufferedReader输入流来读取URL的响应
        BufferedReader in = null;
        in = new BufferedReader(
                new InputStreamReader(connection.getInputStream(), encoding));
        String result = "";
        String getLine;
        while ((getLine = in.readLine()) != null) {
            result += getLine;
        }
        in.close();
        System.err.println("result:" + result);
        return result;
    }
    
  • 相关阅读:
    python工具——geoplotlib
    python工具——playwright
    python工具——folium
    python工具——basemap使用二绘制中国地图
    python工具——basemap使用一基本使用
    python工具——Py-Spy
    Ubuntu 安装python3及多版本切换
    PDI(Kettle)的使用七 定时调度
    go 结构体
    Django部属到Windows IIS所遇到的问题及解决方法
  • 原文地址:https://www.cnblogs.com/L-L-ALICE/p/14910326.html
Copyright © 2011-2022 走看看