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"}}

  • 相关阅读:
    循序渐进做项目系列(3):迷你QQ篇(1)——实现客户端互相聊天
    清明时节欲断魂——未知死焉知生?——向死而生!
    curl基本使用
    some tools
    redis源码学习
    设计模式
    object-c基础
    python库
    awk命令
    gcc编译
  • 原文地址:https://www.cnblogs.com/baldermurphy/p/14323793.html
Copyright © 2011-2022 走看看