0
我知道這已被回答10,000次以上。我一直在閱讀和測試建議超過一個小時,沒有任何進展。Java HttpURLConnection OutputStreamWriter爲空
在下面的代碼中,請求體總是空的。
URL url = new URL("[REMOVED]");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("Authorization", "Bearer [REMOVED]");
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/json");
conn.setDoOutput(true);
conn.setDoInput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write("ABC");
writer.flush();
writer.close();
String line;
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
該記錄在服務器上創建,但正文始終爲空。
任何幫助表示讚賞。