当前位置: 软件>java软件
HTTP+SPDY 客户端开发包 okhttp
本文导语: okhttp 是一个 Java 的 HTTP+SPDY 客户端开发包,同时也支持 Android。 示例代码: OkHttpClient client = new OkHttpClient(); String get(URL url) throws IOException { HttpURLConnection connection = client.open(url); InputStream in = null; try { ...
okhttp 是一个 Java 的 HTTP+SPDY 客户端开发包,同时也支持 Android。
示例代码:
OkHttpClient client = new OkHttpClient(); String get(URL url) throws IOException { HttpURLConnection connection = client.open(url); InputStream in = null; try { // Read the response. in = connection.getInputStream(); byte[] response = readFully(in); return new String(response, "UTF-8"); } finally { if (in != null) in.close(); } }