1

I'm trying to Open the connection using okhttp.

something like,

urlConnection = client.open(url);

does not work with the new ok-http.jar file.

It was working with 1.5.x of okhttp version

Any suggestions?

Thanks

Eduardo Briguenti Vieira
  • 4,351
  • 3
  • 37
  • 49
user2334150
  • 11
  • 1
  • 2
  • What does it means "it does not work"??? Does it fails at compile time or runtime? What kind of error does it shows? – acrespo Jan 12 '16 at 19:25

2 Answers2

0

Code from documentation

public static void main(String[] args) throws IOException {
    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()
        .url("http://kenumir.pl/")
        .build();

    Response response = client.newCall(request).execute();
    System.out.println(response.body().string());
}

Method execute is the key ;-)

Kenumir
  • 664
  • 8
  • 24
0

What does it means "it does not work"??? Does it fails at compile time or runtime? What kind of error does it shows? As of OkHttip 2.x.x, there's been a change in the way to open HttpUrlConnections, you need to include a new module and this should work:

// OkHttp 1.x:
HttpURLConnection connection = client.open(url);

// OkHttp 2.x:
HttpURLConnection connection = new OkUrlFactory(client).open(url);

see OkHttp Release notes for more information .

acrespo
  • 1,134
  • 1
  • 10
  • 33