okhttp 3.3.1 发布,该版本主要是 Bug 修复,包括: Fix: The plaintext check in HttpLoggingInterceptor incorrectly classified newline characters as control characters. This is fixed. Fix: Don't crash reading non-ASCII characters in HTTP/2 headers or in cached HTTP headers. Fix: Retain the response body when an attempt to open a web socket returns a non-101 response code.
okhttp 是一个 Java 的 HTTP+SPDY 客户端开发包,同时也支持 Android。 示例代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | OkHttpClient client = new OkHttpClient();
String get(URL url) throws IOException {
HttpURLConnection connection = client.open(url);
InputStream in = null ;
try {
in = connection.getInputStream();
byte [] response = readFully(in);
return new String(response, "UTF-8" );
} finally {
if (in != null ) in.close();
}
}
|
|