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(); } }
评论