POST:data-raw:Java端request接收方式
HTTP有個方法是使用data-raw的方式將JSON字串POST
給Server。
data-raw request example
1 2 3 4
| curl --location --request POST 'http://localhost/api/getExample' \ --header 'Authorization: xxx' \ --header 'Content-Type: application/json' \ --data-raw '{"authToken": "1a9240cedb9ecddfe3639aceabc6866cb84135c2446f2ed53d9cf992c5d1bd","timestamp":1590394416619}'
|
Java Servlet request處理方式
1 2 3 4 5
| String requestJSON = getJSONParameters(request); private String getJSONParameters(HttpServletRequest request) throws IOException { String json = request.getReader().lines().reduce("", (accumulator, actual) -> accumulator + actual); return json; }
|