<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>润物无声 &#187; SPDY</title>
	<atom:link href="http://blog.zhourunsheng.com/tag/spdy/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zhourunsheng.com</link>
	<description>天空一朵雨做的云</description>
	<lastBuildDate>Sat, 08 May 2021 05:17:21 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Android网络编程之SPDY</title>
		<link>http://blog.zhourunsheng.com/2013/08/android%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b9%8bspdy/</link>
		<comments>http://blog.zhourunsheng.com/2013/08/android%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b9%8bspdy/#comments</comments>
		<pubDate>Thu, 22 Aug 2013 01:33:06 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[移动开发]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[SPDY]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=1807</guid>
		<description><![CDATA[<p>Android的网络编程大家基本都熟悉，Http的Get，Post请求与其他语言的开发大同小异，可以采用And [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/android%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b9%8bspdy/">Android网络编程之SPDY</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>Android的网络编程大家基本都熟悉，Http的Get，Post请求与其他语言的开发大同小异，可以采用Android自带的网络开发包，也可以采用Apache的开源网络编程包。本文介绍一个支持SPDY的开发包<a href="http://square.github.io/okhttp/" target="_blank">OkHttp</a>，关于SPDY的知识，大家可以从<a href="http://zh.wikipedia.org/wiki/SPDY" target="_blank">维基百科</a>和<a href="http://baike.baidu.com/view/2984528.htm" target="_blank">百度百科</a>上面找到，基本就是增强版的Http。</p>
<p>OkHttp is an HTTP client that’s efficient by default:</p>
<ul>
<li>SPDY support allows all requests to the same host to share a socket.</li>
<li>Connection pooling reduces request latency (if SPDY isn’t available).</li>
<li>Transparent GZIP shrinks download sizes.</li>
<li>Response caching avoids the network completely for repeat requests.</li>
</ul>
<p><span id="more-1807"></span></p>
<h3>示例代码</h3>
<h4>GET A URL</h4>
<p>This program downloads a URL and print its contents as a string. <a href="https://raw.github.com/square/okhttp/master/samples/guide/src/main/java/com/squareup/okhttp/guide/GetExample.java">Full source</a>.</p>
<pre>    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();
      }
    }</pre>
<h4>POST TO A SERVER</h4>
<p>This program posts data to a service. <a href="https://raw.github.com/square/okhttp/master/samples/guide/src/main/java/com/squareup/okhttp/guide/PostExample.java">Full source</a>.</p>
<pre>    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();
      }
    }</pre>
<h4>MAVEN 依赖库配置</h4>
<pre>&lt;dependency&gt;
  &lt;groupId&gt;com.squareup.okhttp&lt;/groupId&gt;
  &lt;artifactId&gt;okhttp&lt;/artifactId&gt;
  &lt;version&gt;1.2.0&lt;/version&gt;
&lt;/dependency&gt;</pre>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/android%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b9%8bspdy/">Android网络编程之SPDY</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2013/08/android%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b9%8bspdy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
