• Vert.x HttpClient


    1、加入依赖

    <dependency>
     <groupId>io.vertx</groupId>
     <artifactId>vertx-web-client</artifactId>
     <version>3.8.5</version>
    </dependency>
    

    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<Buffer> 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

  • 相关阅读:
    重定向与转发比较
    servlet_5
    servlet_4
    servlet_3
    字符串的操作以及格式化的操作
    2019的Python
    函数2
    函数
    文件操作
    集合 set
  • 原文地址:https://www.cnblogs.com/tangjizhong/p/13131998.html
Copyright © 2020-2023  润新知