OkHttp輕量的 Java 網(wǎng)絡(luò)請求框架
okhttp 是一個 Java 的 HTTP+SPDY 客戶端開發(fā)包,同時也支持 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();
}
}評論
圖片
表情
