Retrieve HTTP Body in NanoHTTPD

前端 未结 3 1305
一生所求
一生所求 2021-02-07 03:01

How can I retrieve the HTTP POST request body when implementing NanoHTTPDs serve method?

I\'ve tried to use the getInputStream() m

3条回答
  •  野性不改
    2021-02-07 03:59

    I think session.getQueryParameterString(); not work in this case.

    If you using POST, PUT, you should want to try this code:

    Integer contentLength = Integer.parseInt(session.getHeaders().get("content-length"));
    byte[] buffer = new byte[contentLength];
    session.getInputStream().read(buffer, 0, contentLength);
    Log.d("RequestBody: " + new String(buffer));
    

    In fact, I tried IOUtils.toString(inputstream, encoding) but it cause Timeout exception!

提交回复
热议问题