需要导入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); }