public static String postBody(String urlPath, String json, String tk) throws Exception {
        String body = "";
        URL url = new URL(urlPath);
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
        urlConnection.setRequestProperty("Authorization", "Bearer " + tk);
        try( OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());) {
            out.write(json);
            out.flush();
            InputStream inputStream = urlConnection.getInputStream();
            String encoding = urlConnection.getContentEncoding();
            body = IOUtils.toString(inputStream, encoding);
            if (urlConnection.getResponseCode() != 200 && urlConnection.getResponseCode() != 201) {
                throw new IOException() ;
            }
            return body;
        } catch (IOException e) {
           
        }
        return body;
    }   
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 3 个月前
8c391e04 6 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐