Vert.x HttpClient

2021-02-04 23:14

阅读:371

标签:end   baidu   response   发送请求   http   depend   https   web   lan   

1、加入依赖

io.vertx
 vertx-web-client
 3.8.5

2、编写GET请求

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;


public class MainVerticle extends AbstractVerticle {
    public static void main(String[] args) {
        Vertx.vertx().deployVerticle(new MainVerticle());
    }

    @Override
    public void start() throws Exception {
        WebClient client = WebClient.create(vertx);
        client.getAbs("http://www.baidu.com").send(ar -> {
            if (ar.succeeded()) {
                HttpResponse response = ar.result();
                System.out.println(response.body().toString());
            } else {
                System.out.println("发送请求失败:" + ar.cause().getMessage());
            }
        });
    }
}

POST请求和更多解释请到我的独立博客看原文 https://dev-tang.com/post/2020/06/httpclient-vert.x.html

Vert.x HttpClient

标签:end   baidu   response   发送请求   http   depend   https   web   lan   

原文地址:https://www.cnblogs.com/tangjizhong/p/13131998.html


评论


亲,登录后才可以留言!