當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClient.getNow方法代碼示例

本文整理匯總了Java中io.vertx.core.http.HttpClient.getNow方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClient.getNow方法的具體用法?Java HttpClient.getNow怎麽用?Java HttpClient.getNow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.http.HttpClient的用法示例。


在下文中一共展示了HttpClient.getNow方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hello3

import io.vertx.core.http.HttpClient; //導入方法依賴的package包/類
@Path("3")
@GET
public void hello3(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	System.err.println("Creating client");
	HttpClientOptions options = new HttpClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	HttpClient client = vertx.createHttpClient(options);
	client.getNow(443,
			"www.google.com", 
			"/robots.txt", 
			resp -> {
				System.err.println("Got response");
				resp.bodyHandler(body -> {
					System.err.println("Got body");
					asyncResponse.resume(Response.ok(body.toString()).build());
				});
			});
	System.err.println("Created client");
}
 
開發者ID:FroMage,項目名稱:redpipe,代碼行數:24,代碼來源:MyResource.java

示例2: hello4

import io.vertx.core.http.HttpClient; //導入方法依賴的package包/類
@Path("4")
@GET
public void hello4(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	System.err.println("Creating client");
	HttpClientOptions options = new HttpClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	HttpClient client = vertx.createHttpClient(options);
	ObservableHandler<HttpClientResponse> responseHandler = RxHelper.observableHandler();
	client.getNow(443,
			"www.google.com", 
			"/robots.txt", 
			responseHandler.toHandler());
	
	ObservableHandler<Buffer> bodyHandler = RxHelper.observableHandler();
	responseHandler.subscribe(resp -> {
		System.err.println("Got response");
		resp.bodyHandler(bodyHandler.toHandler());
	});
	
	bodyHandler.subscribe(body -> {
		System.err.println("Got body");
		asyncResponse.resume(Response.ok(body.toString()).build());
	});
	System.err.println("Created client");
}
 
開發者ID:FroMage,項目名稱:redpipe,代碼行數:30,代碼來源:MyResource.java

示例3: testGet

import io.vertx.core.http.HttpClient; //導入方法依賴的package包/類
@Test(timeout = 3000L)
public void testGet(TestContext context) throws Exception {
    HttpClient client = vertx.createHttpClient();
    Async async = context.async();
    client.getNow(port, "localhost", "/todos/164", response -> response.bodyHandler(body -> {
        context.assertEquals(getTodoFromJson(body.toString()), todoEx);
        client.close();
        async.complete();
    }));
}
 
開發者ID:sczyh30,項目名稱:todo-backend-vert.x,代碼行數:11,代碼來源:TodoApiTest.java

示例4: testSampleService

import io.vertx.core.http.HttpClient; //導入方法依賴的package包/類
@Test
public void testSampleService(TestContext context) {

    final Async async = context.async();
    HttpClient client = vertx.createHttpClient();
    int deployedHttpPort = Verticle.Facade.deploymentOptions.getConfig().getInteger("http-port");

    // Any id should be accepted in this first test implementation
    client.getNow(
            deployedHttpPort, "localhost", "/scale/13",
            response -> {
                response.handler(body -> {
                    context.assertTrue(body.toString().contains("#13"));
                });
            });

    // Negative ids are incorrect, they should be rejected
    client.getNow(
            deployedHttpPort, "localhost", "/scale/-13",
            response -> {
                response.handler(body -> {
                    context.assertTrue(body.toString().contains("does not exist"));
                });
            });

    async.complete();
}
 
開發者ID:lysid,項目名稱:scales,代碼行數:28,代碼來源:ScalesIntegrationTests.java


注:本文中的io.vertx.core.http.HttpClient.getNow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。