javaokhttpspdy

How to use OkHttp to connect to SPDY website?


I can't get OkHttp to connect to https://www.google.com using SPDY. I used the simplest code sample to send a GET request to the site, and added a bunch of logs in the OkHttp source code to realize that the code kept creating HttpConnection, not a single SPDYConnection. Also, the ConnectionPool was empty the whole time. I am sure I was missing something because I couldn't get any of the biggest benefits: connection pooling and SPDY to work in OkHttp.

My client code:

for (int i = 0; i < 100; i++) {
  Request request = new Request.Builder().url("https://www.google.com").build();
  Response response = client.newCall(request).execute();
}

Why:

What is the 'correct' way to connect to SPDY website?


Solution

  • Adding

    -Xbootclasspath/p:/home/lee/.m2/repository/org/mortbay/jetty/npn/npn-boot/1.1.7.v20140316/npn-boot-1.1.7.v20140316.jar 
    

    to JVM args fixed it for me. Now I can see SPDY connection is up.