io.vertx.ext.web.client.WebClient.get()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中io.vertx.ext.web.client.WebClient.get()方法的一些代码示例,展示了WebClient.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.get()方法的具体详情如下:
包路径:io.vertx.ext.web.client.WebClient
类名称:WebClient
方法名:get

WebClient.get介绍

暂无

代码示例

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  WebClient client = WebClient.create(vertx);

  client.get(8080, "localhost", "/").send(ar -> {
   if (ar.succeeded()) {
    HttpResponse<Buffer> response = ar.result();
    System.out.println("Got HTTP response with status " + response.statusCode() + " with data " +
     response.body().toString("ISO-8859-1"));
   } else {
    ar.cause().printStackTrace();
   }
  });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  WebClient client = WebClient.create(vertx);

  client.get(8080, "localhost", "/")
   .as(BodyCodec.json(User.class))
   .send(ar -> {
    if (ar.succeeded()) {
     HttpResponse<User> response = ar.result();
     System.out.println("Got HTTP response body");
     User user = response.body();
     System.out.println("FirstName " + user.firstName);
     System.out.println("LastName " + user.lastName);
     System.out.println("Male " + user.male);
    } else {
     ar.cause().printStackTrace();
    }
   });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

private void invoke(RoutingContext rc) {
  client.get("/luke").as(BodyCodec.string()).send(ar -> {
   if (ar.failed()) {
    rc.response().end("Unable to call the greeting service: " + ar.cause().getMessage());
   } else {
    if (ar.result().statusCode() != 200) {
     rc.response().end("Unable to call the greeting service - received status:" + ar.result().statusMessage());
    } else {
     rc.response().end("Greeting service invoked: '" + ar.result().body() + "'");
    }
   }
  });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  WebClient client = WebClient.create(vertx);

  client.get(8080, "localhost", "/")
   .as(BodyCodec.jsonObject())
   .send(ar -> {
    if (ar.succeeded()) {
     HttpResponse<JsonObject> response = ar.result();
     System.out.println("Got HTTP response body");
     System.out.println(response.body().encodePrettily());
    } else {
     ar.cause().printStackTrace();
    }
   });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  WebClient client = WebClient.create(vertx);

  client.get(8080, "localhost", "/")
   .addQueryParam("firstName", "Dale")
   .addQueryParam("lastName", "Cooper")
   .addQueryParam("male", "true")
   .send(ar -> {
    if (ar.succeeded()) {
     HttpResponse<Buffer> response = ar.result();
     System.out.println("Got HTTP response with status " + response.statusCode());
    } else {
     ar.cause().printStackTrace();
    }
   });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  // Create the web client and enable SSL/TLS with a trust store
  WebClient client = WebClient.create(vertx,
   new WebClientOptions()
    .setSsl(true)
    .setTrustStoreOptions(new JksOptions()
     .setPath("client-truststore.jks")
     .setPassword("wibble")
    )
  );

  client.get(8443, "localhost", "/")
   .send(ar -> {
    if (ar.succeeded()) {
     HttpResponse<Buffer> response = ar.result();
     System.out.println("Got HTTP response with status " + response.statusCode());
    } else {
     ar.cause().printStackTrace();
    }
   });
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Create an HTTP GET request to send to the server at the specified host and default port.
 * @param host the host
 * @param requestURI the relative URI
 * @return an HTTP client request object
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> get(String host, String requestURI) { 
 io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> ret = io.vertx.rxjava.ext.web.client.HttpRequest.newInstance(delegate.get(host, requestURI), io.vertx.rxjava.core.buffer.Buffer.__TYPE_ARG);
 return ret;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Create an HTTP GET request to send to the server at the default host and port.
 * @param requestURI the relative URI
 * @return an HTTP client request object
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> get(String requestURI) { 
 io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> ret = io.vertx.rxjava.ext.web.client.HttpRequest.newInstance(delegate.get(requestURI), io.vertx.rxjava.core.buffer.Buffer.__TYPE_ARG);
 return ret;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Create an HTTP GET request to send to the server at the specified host and port.
 * @param port the port
 * @param host the host
 * @param requestURI the relative URI
 * @return an HTTP client request object
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> get(int port, String host, String requestURI) { 
 io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> ret = io.vertx.rxjava.ext.web.client.HttpRequest.newInstance(delegate.get(port, host, requestURI), io.vertx.rxjava.core.buffer.Buffer.__TYPE_ARG);
 return ret;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Create an HTTP GET request to send to the server at the default host and port.
 * @param requestURI the relative URI
 * @return an HTTP client request object
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> get(String requestURI) { 
 io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> ret = io.vertx.rxjava.ext.web.client.HttpRequest.newInstance(delegate.get(requestURI), io.vertx.rxjava.core.buffer.Buffer.__TYPE_ARG);
 return ret;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Create an HTTP GET request to send to the server at the specified host and port.
 * @param port the port
 * @param host the host
 * @param requestURI the relative URI
 * @return an HTTP client request object
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> get(int port, String host, String requestURI) { 
 io.vertx.rxjava.ext.web.client.HttpRequest<io.vertx.rxjava.core.buffer.Buffer> ret = io.vertx.rxjava.ext.web.client.HttpRequest.newInstance(delegate.get(port, host, requestURI), io.vertx.rxjava.core.buffer.Buffer.__TYPE_ARG);
 return ret;
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testTimeout() throws Exception {
 AtomicInteger count = new AtomicInteger();
 server.requestHandler(req -> count.incrementAndGet());
 startServer();
 HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
 get.timeout(50).send(onFailure(err -> {
  assertTrue(err instanceof TimeoutException);
  testComplete();
 }));
 await();
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testUserAgentHeaderRemoved() throws Exception {
 testRequest(client -> {
  HttpRequest<Buffer> request = client.get("somehost", "somepath");
  request.headers().remove(HttpHeaders.USER_AGENT);
  return request;
 }, req -> assertEquals(Collections.emptyList(), req.headers().getAll(HttpHeaders.USER_AGENT)));
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testVirtualHost() throws Exception {
 server.requestHandler(req -> {
  assertEquals("another-host:8080", req.host());
  req.response().end();
 });
 startServer();
 HttpRequest<Buffer> req = client.get("/test").virtualHost("another-host");
 req.send(onSuccess(resp -> testComplete()));
 await();
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testCustomUserAgent() throws Exception {
 client = WebClient.wrap(super.client, new WebClientOptions().setUserAgent("smith"));
 testRequest(client -> client.get("somehost", "somepath"), req -> assertEquals(Collections.singletonList("smith"), req.headers().getAll(HttpHeaders.USER_AGENT)));
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testBearerTokenAuthentication() throws Exception {
 testRequest(
  client -> client.get("somehost", "somepath").bearerTokenAuthentication("sometoken"),
  req -> {
   String auth = req.headers().get(HttpHeaders.AUTHORIZATION);
   assertEquals("Was expecting authorization header to contain a bearer token authentication string", "Bearer sometoken", auth);
  }
 );
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testBasicAuthentication() throws Exception {
 testRequest(
  client -> client.get("somehost", "somepath").basicAuthentication("ém$¨=!$€", "&@#§$*éà#\"'"),
  req -> {
   String auth = req.headers().get(HttpHeaders.AUTHORIZATION);
   assertEquals("Was expecting authorization header to contain a basic authentication string", "Basic w6ltJMKoPSEk4oKsLSZAI8KnJCrDqcOgIyIn", auth);
  }
 );
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testQueryParam() throws Exception {
 testRequest(client -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/").addQueryParam("param", "param_value"), req -> {
  assertEquals("param=param_value", req.query());
  assertEquals("param_value", req.getParam("param"));
 });
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testOverwriteQueryParams() throws Exception {
 testRequest(client -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/?param=param_value1").setQueryParam("param", "param_value2"), req -> {
  assertEquals("param=param_value2", req.query());
  assertEquals("param_value2", req.getParam("param"));
 });
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testQueryParamAppend() throws Exception {
 testRequest(client -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/?param1=param1_value1").addQueryParam("param1", "param1_value2").addQueryParam("param2", "param2_value"), req -> {
  assertEquals("param1=param1_value1&param1=param1_value2&param2=param2_value", req.query());
  assertEquals("param1_value1", req.getParam("param1"));
  assertEquals("param2_value", req.getParam("param2"));
 });
}

相关文章