NanoHTTPD的post数据提取

    private JSONObject parseBody(IHTTPSession session) {

        Map<String, String> files = new HashMap<String, String>();

        JSONObject json = null;
        Method method = session.getMethod();
        LogPrint.d("parseBody  Method is "+method.toString());
//         if(NanoHTTPD.Method.GET.equals(method)){
//             //get方式
//             String queryParams = session.getQueryParameterString();
//         }else
        if (NanoHTTPD.Method.POST.equals(method)) {
            //post方式
            try {
                session.parseBody(files);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ResponseException e) {
                e.printStackTrace();
            }
            LogPrint.d("post body1 is "+files.toString());
            String body=files.get("postData");
            //String body = session.getQueryParameterString();
            if(body==null){
                return null;
            }
            LogPrint.d("post body is "+body);
            try {
                json = new JSONObject(body);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return json;
    }

数据其实是这样的

post body1 is {postData={"sn": "123456789","time": 1589472000,"ip": "192.168.222.77","mac": "00-16-EA-AE-3D-40","keepalive": 30,"signMethod": "md5","sign": "e10adc3949ba59abbe56e057f20f883e"}}

原文地址:https://www.cnblogs.com/baldermurphy/p/14323793.html