幽沉谢世事,俯默窥唐虞。这篇文章主要讲述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);
推荐阅读
- 运行bee run之后出现的错误以及解决方法Failed to build the application:
- Android的类模板源码
- appium启动uiautomator2步骤(window系统)
- app.vue基本模板
- org.apache.ibatis.binding.BindingException: Type interface cn.dao.UserDao is not known to the Mapper
- Android VideoView未解决,动态读取权限BottomNavigationView的用法
- Appium自动化-Android
- 其它测试(回归测试冒烟测试APP测试联调测试确认测试随机测试安全测试探索性测试)
- Android Framework 学习(屏幕刷新机制)