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

  • 相关阅读:
    JSP 服务器响应
    JSP 客户端请求
    杂烩笔记
    ExtJS panel
    DB2存储过程语法规则
    CentOS查看软件源提供的软件版本命令
    Linux查看程序端口占用情况【转】
    359. Logger Rate Limiter
    358. Rearrange String k Distance Apart
    357. Count Numbers with Unique Digits
  • 原文地址:https://www.cnblogs.com/baldermurphy/p/14323793.html
Copyright © 2011-2022 走看看