| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
11年前发布

HTTP+SPDY 客户端Java开发包:okhttp

okhttp 是一个 Java 的 HTTP+SPDY 客户端开发包,同时也支持 Android。

kHttp is an HTTP client that’s efficient by default:

  • SPDY support allows all requests to the same host to share a socket.
  • Connection pooling reduces request latency (if SPDY isn’t available).
  • Transparent GZIP shrinks download sizes.
  • Response caching avoids the network completely for repeat requests.

示例代码:

   OkHttpClient client = new OkHttpClient();        String post(URL url, byte[] body) throws IOException {        HttpURLConnection connection = client.open(url);        OutputStream out = null;        InputStream in = null;        try {          // Write the request.          connection.setRequestMethod("POST");          out = connection.getOutputStream();          out.write(body);          out.close();            // Read the response.          if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {            throw new IOException("Unexpected HTTP response: "                + connection.getResponseCode() + " " + connection.getResponseMessage());          }          in = connection.getInputStream();          return readFirstLine(in);        } finally {          // Clean up.          if (out != null) out.close();          if (in != null) in.close();        }      }

项目主页:http://www.open-open.com/lib/view/home/1383139543921

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1383139543921.html
网络工具包 OkHttp