2017-02-08 3 views
1

vertx HttpClient에 문제가 있습니다. vertx와 plain java를 사용하여 테스트를 수행하는 코드입니다. getHTML()가 여기에서이다Vertx HttpClient getNow가 작동하지 않습니다.

Vertx vertx = Vertx.vertx(); 
    HttpClientOptions options = new HttpClientOptions() 
      .setTrustAll(true) 
      .setSsl(false) 
      .setDefaultPort(80) 
      .setProtocolVersion(HttpVersion.HTTP_1_1) 
      .setLogActivity(true); 
    HttpClient client = vertx.createHttpClient(options); 

    client.getNow("google.com", "/", response -> { 
     System.out.println("Received response with status code " + response.statusCode()); 
    }); 
    System.out.println(getHTML("http://google.com")); 

: How do I do a HTTP GET in Java?

이 내 출력 :

<!doctype html><html... etc <- correct output from plain java 
Feb 08, 2017 11:31:21 AM io.vertx.core.http.impl.HttpClientRequestImpl 
SEVERE: java.net.UnknownHostException: failed to resolve 'google.com'.  Exceeded max queries per resolve 3 

그러나 vertx는 연결할 수 없습니다. 여기 뭐가 잘못 됐니? 나는 어떤 프록시도 사용하지 않고있다.

+1

수 있습니다. Vert.x 3.4.0.Beta1을 사용해 볼 수 있습니까? 이 버전에서 수정해야합니다. 또한'-Dvertx.disableDnsResolver = true'를 사용하여 JVM 해결 자로 폴백 할 수 있습니다. – tsegismont

+0

3.3.3 및 3.4.0.Beta1 모두 시도했지만 작동하지 않습니다. 이 jvm 매개 변수를 확인할 것입니다. –

+1

-Dvertx.disableDnsResolver = true works :) 이 질문에 답하십시오 (동의 할 것입니다). –

답변

0

다음은 저에게 적합한 샘플 코드입니다. https://github.com/eclipse/vert.x/issues/1753 관련

public class TemplVerticle extends HttpVerticle { 

public static void main(String[] args) { 
    Vertx vertx = Vertx.vertx(); 

    // Create the web client and enable SSL/TLS with a trust store 
    WebClient client = WebClient.create(vertx, 
      new WebClientOptions() 
        .setSsl(true) 
        .setTrustAll(true) 
        .setDefaultPort(443) 
        .setKeepAlive(true) 
        .setDefaultHost("www.w3schools.com") 

    ); 


    client.get("www.w3schools.com") 

      .as(BodyCodec.string()) 
      .send(ar -> { 
       if (ar.succeeded()) { 
        HttpResponse<String> response = ar.result(); 
        System.out.println("Got HTTP response body"); 
        System.out.println(response.body().toString()); 

       } else { 
        ar.cause().printStackTrace(); 
       } 
      }); 
} 

}

관련 문제