码迷,mamicode.com
首页 > 移动开发 > 详细

Android Simple Http Server

时间:2020-06-08 16:11:29      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:set   nbsp   erp   time   row   reg   ati   exce   str   

添加httpcore

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

新建一个服务

重写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);

 

Android Simple Http Server

标签:set   nbsp   erp   time   row   reg   ati   exce   str   

原文地址:https://www.cnblogs.com/JebediahKerman/p/13066285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!