Retrieve HTTP Body in NanoHTTPD

前端 未结 3 1307
一生所求
一生所求 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 04:01

    On a IHTTPSession instance you can call the .parseBody(Map) method which will then fill the map you provided with some values.

    Afterwards your map may contain a value under the key postBody.

            final HashMap map = new HashMap();
            session.parseBody(map);
            final String json = map.get("postData");
    

    This value will then hold your posts body.

    Code that does this, can be found here.

提交回复
热议问题