3 回答

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊
你在找這個(gè)嗎?
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StringBuilder sb = new StringBuilder();
BufferedReader reader = request.getReader();
try {
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
}
} finally {
reader.close();
}
System.out.println(sb.toString());
}

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊
還有另一種方法,org.apache.commons.io.IOUtils用于從請(qǐng)求中提取字符串
String jsonString = IOUtils.toString(request.getInputStream());
然后,您可以執(zhí)行所需的任何操作,將其轉(zhuǎn)換為JSON或其他對(duì)象Gson,等等。
JSONObject json = new JSONObject(jsonString);
MyObject myObject = new Gson().fromJson(jsonString, MyObject.class);
- 3 回答
- 0 關(guān)注
- 518 瀏覽
添加回答
舉報(bào)