有没有人知道一个用
Java编写的能够在
Android上托管REST服务的开源Web服务器?
我倾向于https://github.com/NanoHttpd/nanohttpd,但它需要从头开始编写Web服务框架.
PS. Websockets将是一个加号.
PS2.我正在寻找托管解决方案而不是客户端,设备功能强大.
解决方法
面对类似的问题,我们选择使用Koush的AndroidAsync:
https://github.com/koush/AndroidAsync
由于各种原因,这是一个非常方便的项目.除了支持websockets,你可以在几行中实现一个基本的POST或GET处理程序,并传递JSON,这就是我们所需要的.来自该github页面的示例(以相同的方式支持POST):
AsyncHttpServer server = new AsyncHttpServer();
List<WebSocket> _sockets = new ArrayList<WebSocket>();
server.get("/",new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request,AsyncHttpServerResponse response) {
response.send("Hello!!!");
}
});
// listen on port 5000
server.listen(5000);
// browsing http://localhost:5000 will return Hello!!!