OkHttp轻量的 Java 网络请求框架
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(); } }
评论