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 block e.printStackTrace(); } catch (ResponseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return super.serve(session); } }
NanoHTTPD post json
最新推荐文章于 2023-11-15 16:32:42 发布