从品牌网站建设到网络营销策划,从策略到执行的一站式服务
最近遇到一个需求需要在App中创建一个Http服务器供供浏览器调用,用了下开源的微型Htpp服务器框架:NanoHttpd,项目地址:https://github.com/NanoHttpd/nanohttpd
直接上代码
public class HttpServer extends NanoHTTPD { public HttpServer(int port) { super(port); } @Override public Response serve(IHTTPSession session) { HashMapfiles = new HashMap<>(); Method method = session.getMethod(); if (Method.POST.equals(method)) { try { //notice:If the post with body data, it needs parses the body,or it can't get the body data; session.parseBody(files); }catch (IOException e) { return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + e.getMessage()); }catch (ResponseException e) { return newFixedLengthResponse(e.getStatus(), MIME_PLAINTEXT, e.getMessage()); } } final String postData = files.get("postData"); String transJson = Transmit.getInstance().getAuthoriseData(postData); return newFixedLengthResponse(transJson); }
成都网站建设公司地址:成都市青羊区太升南路288号锦天国际A座10层 建设咨询028-86922220
成都快上网科技有限公司-四川网站建设设计公司 | 蜀ICP备19037934号 Copyright 2020,ALL Rights Reserved cdkjz.cn | 成都网站建设 | © Copyright 2020版权所有.
专家团队为您提供成都网站建设,成都网站设计,成都品牌网站设计,成都营销型网站制作等服务,成都建网站就找快上网! | 成都网站建设哪家好? | 网站建设地图