改写JfinalConfig中的 onStart事件,在服务器启动时,请求本服务器的接口
public static void main(String[] args) {
UndertowServer.start(WebConfig.class, 80, true);
}
@Override
public void onStart() {
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("http://localhost:80/test/index").build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}catch(IOException e){
e.printStackTrace();
}
}
输出异常 java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:80
工作中有一个需求,需要在启动服务器之后调用钉钉的注册回调地址api,钉钉会回向回调地址发送一个请求,但是会失败报服务器502。工作中使用的是4.3版本。