Android Simple Http Server

幽沉谢世事,俯默窥唐虞。这篇文章主要讲述Android Simple Http Server相关的知识,希望能为你提供帮助。
添加httpcore

implementation ‘org.apache.httpcomponents:httpcore:4.4.13‘

【Android Simple Http Server】新建一个服务
重写onCreate方法
super.onCreate(); HttpRequestHandler handler = new HttpRequestHandler() { @Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setStatusCode(HttpStatus.SC_OK); response.setEntity(new StringEntity("< h3> Hello World!< /h3> ", ContentType.TEXT_html)); } }; HttpServer server = ServerBootstrap.bootstrap() .setListenerPort(8880) .registerHandler("*", handler) .create(); try { server.start(); } catch (Exception e) { }

重写onDestory方法
super.onDestroy(); server.shutdown(0, TimeUnit.SECONDS);

 

    推荐阅读