NanoHTTPD post json

来源:互联网 发布:企业海关数据查询 编辑:程序博客网 时间:2024/06/09 17:34
public class RemoteServerNanoHTTPD extends NanoHTTPD{public RemoteServerNanoHTTPD(int port) {super(port);}public RemoteServerNanoHTTPD(String hostName,int port){super(hostName,port);Log.e("weifang","hostName:"+hostName + " port:" + port);} public Response serve(IHTTPSession session) {  Method method = session.getMethod(); Log.e("weifang","Method:"+method.toString());  if(NanoHTTPD.Method.GET.equals(method)){ //get方式 String queryParams = session.getQueryParameterString(); Log.e("weifang","params:"+queryParams); }else if(NanoHTTPD.Method.POST.equals(method)){ //post方式  Log.e("weifang","into POST"); try {session.parseBody(new HashMap<String, String>());String body = session.getQueryParameterString();JSONObject json = new JSONObject(body);String a = json.getString("a");String b = json.getString("b");String c = json.getString("c");String d = json.getString("d");Log.e("weifang","json:"+ body);Log.e("weifang","a:"+ a + " b:" + b + " c:" + c + " d:" + d);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ResponseException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}  } return super.serve(session); } }

 
原创粉丝点击