Github地址:github.com/NanoHttpd/n…
2、引入代码
两种方式,第一种把官网的代码clone
下来,然后 copy
放到工程;第二种使用别人适配过的库。博主这里使用第二种方式,更加快捷些。
在gradle
里面添加依赖
implementation ‘org.nanohttpd:nanohttpd:2.2.0’
3、启动服务
//自定义一个Server继承NanoHTTPD
public class AndroidWebServer extends NanoHTTPD {
public AndroidWebServer(int port) throws IOException {
super(port);
}
@Override
public Response serve(IHTTPSession session) {
String msg = “
Hello AutoPy
\n”;Map<String, String> parms = session.getParms();
if (parms.get(“code”) == null) {
msg += “\n
Your code:
\n” + “\n”;} else {
msg += "
Hello, " + parms.get(“code”) + “!
”