需要导入nanohttpd2.3,jar包

继承NanoHTTPD

public class HttpServer extends NanoHTTPD {
    public HttpServer(int port)  {
        super(port);
    }

    public static void main(String[] args) {
        try {
            new HttpServer(8090).start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

  @Override
    public Response serve(IHTTPSession session){
        Map<String,String> postMap=new HashMap<String,String>();
        try{
            session.parseBody(postMap);
       } catch(){
          }
        String queryStr=postMap.get(HTTPSession.POST_DATA);
         System.out.println(queryStr);
}                            

 

posted on 2018-12-18 11:39  丁昆  阅读(297)  评论(0编辑  收藏  举报