http post 模板 (设置header + json传参)
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
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;
}
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 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)