1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.squareup.okhttp.internal.http; 18 19import com.squareup.okhttp.OkHttpClient; 20import java.io.BufferedReader; 21import java.io.InputStreamReader; 22import java.net.URL; 23import javax.net.ssl.HostnameVerifier; 24import javax.net.ssl.HttpsURLConnection; 25import javax.net.ssl.SSLSession; 26 27public final class ExternalSpdyExample { 28 public static void main(String[] args) throws Exception { 29 URL url = new URL("https://www.google.ca/"); 30 HttpsURLConnection connection = (HttpsURLConnection) new OkHttpClient().open(url); 31 32 connection.setHostnameVerifier(new HostnameVerifier() { 33 @Override public boolean verify(String s, SSLSession sslSession) { 34 System.out.println("VERIFYING " + s); 35 return true; 36 } 37 }); 38 39 int responseCode = connection.getResponseCode(); 40 System.out.println(responseCode); 41 42 BufferedReader reader = 43 new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); 44 String line; 45 while ((line = reader.readLine()) != null) { 46 System.out.println(line); 47 } 48 } 49} 50