zoukankan      html  css  js  c++  java
  • 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"}}

  • 相关阅读:
    javascript之this的深入学习
    记一次前端面试
    nodejs学习
    Javascript内置对象
    Javascript事件
    全屏滚动插件小结
    Javascript函数的深入学习
    近年来前端开发趋势,MVVM框架,Vue.js的核心思想
    Javascript的for ... in循环
    JavaScript的对象深入学习
  • 原文地址:https://www.cnblogs.com/baldermurphy/p/14323793.html
Copyright © 2011-2022 走看看