xref: /aosp_15_r20/external/okhttp/website/index.html (revision ab625e417e7950f52094c019474d2a9e9f14a68c)
1*ab625e41SAndroid Build Coastguard Worker<!DOCTYPE html>
2*ab625e41SAndroid Build Coastguard Worker<html lang="en">
3*ab625e41SAndroid Build Coastguard Worker  <head>
4*ab625e41SAndroid Build Coastguard Worker    <meta charset="utf-8">
5*ab625e41SAndroid Build Coastguard Worker    <title>OkHttp</title>
6*ab625e41SAndroid Build Coastguard Worker    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7*ab625e41SAndroid Build Coastguard Worker    <meta name="description" content="An HTTP &amp; SPDY client for Android and Java applications">
8*ab625e41SAndroid Build Coastguard Worker    <link href="static/bootstrap-combined.min.css" rel="stylesheet">
9*ab625e41SAndroid Build Coastguard Worker    <link href="static/app.css" rel="stylesheet">
10*ab625e41SAndroid Build Coastguard Worker    <link href="static/app-theme.css" rel="stylesheet">
11*ab625e41SAndroid Build Coastguard Worker    <link href="http://fonts.googleapis.com/css?family=Roboto:400,300italic,100,100italic,300" rel="stylesheet" type="text/css">
12*ab625e41SAndroid Build Coastguard Worker    <!--[if lt IE 9]><script src="static/html5shiv.min.js"></script><![endif]-->
13*ab625e41SAndroid Build Coastguard Worker  </head>
14*ab625e41SAndroid Build Coastguard Worker  <body data-target=".content-nav">
15*ab625e41SAndroid Build Coastguard Worker    <header>
16*ab625e41SAndroid Build Coastguard Worker      <div class="container">
17*ab625e41SAndroid Build Coastguard Worker        <div class="row">
18*ab625e41SAndroid Build Coastguard Worker          <div class="span5">
19*ab625e41SAndroid Build Coastguard Worker            <h1>OkHttp</h1>
20*ab625e41SAndroid Build Coastguard Worker          </div>
21*ab625e41SAndroid Build Coastguard Worker          <div class="span7">
22*ab625e41SAndroid Build Coastguard Worker            <menu>
23*ab625e41SAndroid Build Coastguard Worker              <ul>
24*ab625e41SAndroid Build Coastguard Worker                <li><a href="#download" class="menu download">Download <span class="version-tag">Latest</span></a></li>
25*ab625e41SAndroid Build Coastguard Worker                <li><a href="http://github.com/square/okhttp" data-title="View GitHub Project" class="menu github"><img src="static/icon-github.png" alt="GitHub"/></a></li>
26*ab625e41SAndroid Build Coastguard Worker                <li><a href="http://square.github.io/" data-title="Square Open Source Portal" class="menu square"><img src="static/icon-square.png" alt="Square"/></a></li>
27*ab625e41SAndroid Build Coastguard Worker              </ul>
28*ab625e41SAndroid Build Coastguard Worker            </menu>
29*ab625e41SAndroid Build Coastguard Worker          </div>
30*ab625e41SAndroid Build Coastguard Worker      </div>
31*ab625e41SAndroid Build Coastguard Worker    </header>
32*ab625e41SAndroid Build Coastguard Worker    <section id="subtitle">
33*ab625e41SAndroid Build Coastguard Worker      <div class="container">
34*ab625e41SAndroid Build Coastguard Worker        <div class="row">
35*ab625e41SAndroid Build Coastguard Worker          <div class="span12">
36*ab625e41SAndroid Build Coastguard Worker            <h2>An <strong>HTTP &amp; SPDY</strong> client for Android and Java applications</h2>
37*ab625e41SAndroid Build Coastguard Worker          </div>
38*ab625e41SAndroid Build Coastguard Worker        </div>
39*ab625e41SAndroid Build Coastguard Worker      </div>
40*ab625e41SAndroid Build Coastguard Worker    </section>
41*ab625e41SAndroid Build Coastguard Worker    <section id="body">
42*ab625e41SAndroid Build Coastguard Worker      <div class="container">
43*ab625e41SAndroid Build Coastguard Worker        <div class="row">
44*ab625e41SAndroid Build Coastguard Worker          <div class="span9">
45*ab625e41SAndroid Build Coastguard Worker            <h3 id="overview">Overview</h3>
46*ab625e41SAndroid Build Coastguard Worker            <p>HTTP is the way modern applications network. It’s how we exchange data &amp; media.
47*ab625e41SAndroid Build Coastguard Worker                Doing HTTP efficiently makes your stuff load faster and saves bandwidth.</p>
48*ab625e41SAndroid Build Coastguard Worker
49*ab625e41SAndroid Build Coastguard Worker            <p>OkHttp is an HTTP client that’s efficient by default:</p>
50*ab625e41SAndroid Build Coastguard Worker            <ul>
51*ab625e41SAndroid Build Coastguard Worker                <li>HTTP/2 and SPDY support allows all requests to the same host to share a socket.</li>
52*ab625e41SAndroid Build Coastguard Worker                <li>Connection pooling reduces request latency (if SPDY isn’t available).</li>
53*ab625e41SAndroid Build Coastguard Worker                <li>Transparent GZIP shrinks download sizes.</li>
54*ab625e41SAndroid Build Coastguard Worker                <li>Response caching avoids the network completely for repeat requests.</li>
55*ab625e41SAndroid Build Coastguard Worker            </ul>
56*ab625e41SAndroid Build Coastguard Worker
57*ab625e41SAndroid Build Coastguard Worker            <p>OkHttp perseveres when the network is troublesome: it will silently recover from
58*ab625e41SAndroid Build Coastguard Worker                common connection problems. If your service has multiple IP addresses OkHttp will
59*ab625e41SAndroid Build Coastguard Worker                attempt alternate addresses if the first connect fails. This is necessary for IPv4+IPv6
60*ab625e41SAndroid Build Coastguard Worker                and for services hosted in redundant data centers. OkHttp initiates new connections
61*ab625e41SAndroid Build Coastguard Worker                with modern TLS features (SNI, ALPN), and falls back to TLS 1.0 if the handshake
62*ab625e41SAndroid Build Coastguard Worker                fails.</p>
63*ab625e41SAndroid Build Coastguard Worker
64*ab625e41SAndroid Build Coastguard Worker            <p>Using OkHttp is easy. Its 2.0 API is designed with fluent builders and
65*ab625e41SAndroid Build Coastguard Worker                immutability. It supports both synchronous blocking calls and async calls with
66*ab625e41SAndroid Build Coastguard Worker                callbacks.</p>
67*ab625e41SAndroid Build Coastguard Worker
68*ab625e41SAndroid Build Coastguard Worker            <p>You can try out OkHttp without rewriting your network code. The
69*ab625e41SAndroid Build Coastguard Worker                <code>okhttp-urlconnection</code> module implements the familiar
70*ab625e41SAndroid Build Coastguard Worker                <code>java.net.HttpURLConnection</code> API and the <code>okhttp-apache</code>
71*ab625e41SAndroid Build Coastguard Worker                module implements the Apache <code>HttpClient</code> API.</p>
72*ab625e41SAndroid Build Coastguard Worker
73*ab625e41SAndroid Build Coastguard Worker            <p>OkHttp supports Android 2.3 and above. For Java, the minimum requirement is 1.7.</p>
74*ab625e41SAndroid Build Coastguard Worker
75*ab625e41SAndroid Build Coastguard Worker            <h3 id="examples">Examples</h3>
76*ab625e41SAndroid Build Coastguard Worker            <h4>Get a URL</h4>
77*ab625e41SAndroid Build Coastguard Worker            <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>.
78*ab625e41SAndroid Build Coastguard Worker<pre class="prettyprint">
79*ab625e41SAndroid Build Coastguard WorkerOkHttpClient client = new OkHttpClient();
80*ab625e41SAndroid Build Coastguard Worker
81*ab625e41SAndroid Build Coastguard WorkerString run(String url) throws IOException {
82*ab625e41SAndroid Build Coastguard Worker  Request request = new Request.Builder()
83*ab625e41SAndroid Build Coastguard Worker      .url(url)
84*ab625e41SAndroid Build Coastguard Worker      .build();
85*ab625e41SAndroid Build Coastguard Worker
86*ab625e41SAndroid Build Coastguard Worker  Response response = client.newCall(request).execute();
87*ab625e41SAndroid Build Coastguard Worker  return response.body().string();
88*ab625e41SAndroid Build Coastguard Worker}
89*ab625e41SAndroid Build Coastguard Worker</pre>
90*ab625e41SAndroid Build Coastguard Worker            <h4>Post to a Server</h4>
91*ab625e41SAndroid Build Coastguard Worker            <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>.
92*ab625e41SAndroid Build Coastguard Worker
93*ab625e41SAndroid Build Coastguard Worker<pre class="prettyprint">
94*ab625e41SAndroid Build Coastguard Workerpublic static final MediaType JSON
95*ab625e41SAndroid Build Coastguard Worker    = MediaType.parse("application/json; charset=utf-8");
96*ab625e41SAndroid Build Coastguard Worker
97*ab625e41SAndroid Build Coastguard WorkerOkHttpClient client = new OkHttpClient();
98*ab625e41SAndroid Build Coastguard Worker
99*ab625e41SAndroid Build Coastguard WorkerString post(String url, String json) throws IOException {
100*ab625e41SAndroid Build Coastguard Worker  RequestBody body = RequestBody.create(JSON, json);
101*ab625e41SAndroid Build Coastguard Worker  Request request = new Request.Builder()
102*ab625e41SAndroid Build Coastguard Worker      .url(url)
103*ab625e41SAndroid Build Coastguard Worker      .post(body)
104*ab625e41SAndroid Build Coastguard Worker      .build();
105*ab625e41SAndroid Build Coastguard Worker  Response response = client.newCall(request).execute();
106*ab625e41SAndroid Build Coastguard Worker  return response.body().string();
107*ab625e41SAndroid Build Coastguard Worker}
108*ab625e41SAndroid Build Coastguard Worker</pre>
109*ab625e41SAndroid Build Coastguard Worker
110*ab625e41SAndroid Build Coastguard Worker            <h3 id="download">Download</h3>
111*ab625e41SAndroid Build Coastguard Worker            <p><a href="https://search.maven.org/remote_content?g=com.squareup.okhttp&a=okhttp&v=LATEST" class="dl version-href">&darr; <span class="version-tag">Latest</span> JAR</a></p>
112*ab625e41SAndroid Build Coastguard Worker            <p>You'll also need <a href="http://github.com/square/okio">Okio</a>, which OkHttp
113*ab625e41SAndroid Build Coastguard Worker                uses for fast I/O and resizable buffers. Download the
114*ab625e41SAndroid Build Coastguard Worker                <a href="https://search.maven.org/remote_content?g=com.squareup.okio&a=okio&v=LATEST">latest JAR</a>.
115*ab625e41SAndroid Build Coastguard Worker            <p>The source code to OkHttp, its samples, and this website is <a href="http://github.com/square/okhttp">available on GitHub</a>.</p>
116*ab625e41SAndroid Build Coastguard Worker
117*ab625e41SAndroid Build Coastguard Worker            <h4>Maven</h4>
118*ab625e41SAndroid Build Coastguard Worker            <pre class="prettyprint">&lt;dependency>
119*ab625e41SAndroid Build Coastguard Worker  &lt;groupId>com.squareup.okhttp&lt;/groupId>
120*ab625e41SAndroid Build Coastguard Worker  &lt;artifactId>okhttp&lt;/artifactId>
121*ab625e41SAndroid Build Coastguard Worker  &lt;version><span class="version pln"><em>(insert latest version)</em></span>&lt;/version>
122*ab625e41SAndroid Build Coastguard Worker&lt;/dependency></pre>
123*ab625e41SAndroid Build Coastguard Worker
124*ab625e41SAndroid Build Coastguard Worker            <h4>Gradle</h4>
125*ab625e41SAndroid Build Coastguard Worker            <pre class="prettyprint">compile 'com.squareup.okhttp:okhttp:<span class="version pln"><em>(insert latest version)</em></span>'</pre>
126*ab625e41SAndroid Build Coastguard Worker
127*ab625e41SAndroid Build Coastguard Worker            <h3 id="contributing">Contributing</h3>
128*ab625e41SAndroid Build Coastguard Worker            <p>If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.</p>
129*ab625e41SAndroid Build Coastguard Worker            <p>When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Please also make sure your code compiles by running <code>mvn clean verify</code>.</p>
130*ab625e41SAndroid Build Coastguard Worker            <p>Before your code can be accepted into the project you must also sign the <a href="http://squ.re/sign-the-cla">Individual Contributor License Agreement (CLA)</a>.</p>
131*ab625e41SAndroid Build Coastguard Worker
132*ab625e41SAndroid Build Coastguard Worker            <h3 id="license">License</h3>
133*ab625e41SAndroid Build Coastguard Worker            <pre>Copyright 2014 Square, Inc.
134*ab625e41SAndroid Build Coastguard Worker
135*ab625e41SAndroid Build Coastguard WorkerLicensed under the Apache License, Version 2.0 (the "License");
136*ab625e41SAndroid Build Coastguard Workeryou may not use this file except in compliance with the License.
137*ab625e41SAndroid Build Coastguard WorkerYou may obtain a copy of the License at
138*ab625e41SAndroid Build Coastguard Worker
139*ab625e41SAndroid Build Coastguard Worker   http://www.apache.org/licenses/LICENSE-2.0
140*ab625e41SAndroid Build Coastguard Worker
141*ab625e41SAndroid Build Coastguard WorkerUnless required by applicable law or agreed to in writing, software
142*ab625e41SAndroid Build Coastguard Workerdistributed under the License is distributed on an "AS IS" BASIS,
143*ab625e41SAndroid Build Coastguard WorkerWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144*ab625e41SAndroid Build Coastguard WorkerSee the License for the specific language governing permissions and
145*ab625e41SAndroid Build Coastguard Workerlimitations under the License.</pre>
146*ab625e41SAndroid Build Coastguard Worker          </div>
147*ab625e41SAndroid Build Coastguard Worker          <div class="span3">
148*ab625e41SAndroid Build Coastguard Worker            <div class="content-nav" data-spy="affix" data-offset-top="80">
149*ab625e41SAndroid Build Coastguard Worker              <ul class="nav nav-tabs nav-stacked primary">
150*ab625e41SAndroid Build Coastguard Worker                <li><a href="#overview">Overview</a></li>
151*ab625e41SAndroid Build Coastguard Worker                <li><a href="#examples">Examples</a></li>
152*ab625e41SAndroid Build Coastguard Worker                <li><a href="#download">Download</a></li>
153*ab625e41SAndroid Build Coastguard Worker                <li><a href="#contributing">Contributing</a></li>
154*ab625e41SAndroid Build Coastguard Worker                <li><a href="#license">License</a></li>
155*ab625e41SAndroid Build Coastguard Worker              </ul>
156*ab625e41SAndroid Build Coastguard Worker              <ul class="nav nav-pills nav-stacked secondary">
157*ab625e41SAndroid Build Coastguard Worker                <li><a href="https://github.com/square/okhttp/wiki">Wiki</a></li>
158*ab625e41SAndroid Build Coastguard Worker                <li><a href="2.x/okhttp/">Javadoc</a></li>
159*ab625e41SAndroid Build Coastguard Worker                <li><a href="http://stackoverflow.com/questions/tagged/okhttp?sort=active">StackOverflow</a></li>
160*ab625e41SAndroid Build Coastguard Worker              </ul>
161*ab625e41SAndroid Build Coastguard Worker            </div>
162*ab625e41SAndroid Build Coastguard Worker          </div>
163*ab625e41SAndroid Build Coastguard Worker        </div>
164*ab625e41SAndroid Build Coastguard Worker        <div class="row">
165*ab625e41SAndroid Build Coastguard Worker          <div class="span12 logo">
166*ab625e41SAndroid Build Coastguard Worker            <a href="https://squareup.com"><img src="static/logo-square.png" alt="Square, Inc."/></a>
167*ab625e41SAndroid Build Coastguard Worker          </div>
168*ab625e41SAndroid Build Coastguard Worker        </div>
169*ab625e41SAndroid Build Coastguard Worker      </div>
170*ab625e41SAndroid Build Coastguard Worker    </section>
171*ab625e41SAndroid Build Coastguard Worker    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
172*ab625e41SAndroid Build Coastguard Worker    <script src="static/bootstrap.min.js"></script>
173*ab625e41SAndroid Build Coastguard Worker    <script src="static/jquery.smooth-scroll.min.js"></script>
174*ab625e41SAndroid Build Coastguard Worker    <script src="static/jquery-maven-artifact.min.js"></script>
175*ab625e41SAndroid Build Coastguard Worker    <script src="static/prettify.js"></script>
176*ab625e41SAndroid Build Coastguard Worker    <script type="text/javascript">
177*ab625e41SAndroid Build Coastguard Worker      $(function() {
178*ab625e41SAndroid Build Coastguard Worker        // Syntax highlight code blocks.
179*ab625e41SAndroid Build Coastguard Worker        prettyPrint();
180*ab625e41SAndroid Build Coastguard Worker
181*ab625e41SAndroid Build Coastguard Worker        // Spy on scroll position for real-time updating of current section.
182*ab625e41SAndroid Build Coastguard Worker        $('body').scrollspy();
183*ab625e41SAndroid Build Coastguard Worker
184*ab625e41SAndroid Build Coastguard Worker        // Use smooth-scroll for internal links.
185*ab625e41SAndroid Build Coastguard Worker        $('a').smoothScroll();
186*ab625e41SAndroid Build Coastguard Worker
187*ab625e41SAndroid Build Coastguard Worker        // Enable tooltips on the header nav image items.
188*ab625e41SAndroid Build Coastguard Worker        $('.menu').tooltip({
189*ab625e41SAndroid Build Coastguard Worker          placement: 'bottom',
190*ab625e41SAndroid Build Coastguard Worker          trigger: 'hover',
191*ab625e41SAndroid Build Coastguard Worker          container: 'body',
192*ab625e41SAndroid Build Coastguard Worker          delay: {
193*ab625e41SAndroid Build Coastguard Worker            show: 500,
194*ab625e41SAndroid Build Coastguard Worker            hide: 0
195*ab625e41SAndroid Build Coastguard Worker          }
196*ab625e41SAndroid Build Coastguard Worker        });
197*ab625e41SAndroid Build Coastguard Worker
198*ab625e41SAndroid Build Coastguard Worker        // Look up the latest version of the library.
199*ab625e41SAndroid Build Coastguard Worker        $.fn.artifactVersion({
200*ab625e41SAndroid Build Coastguard Worker          'groupId': 'com.squareup.okhttp',
201*ab625e41SAndroid Build Coastguard Worker          'artifactId': 'okhttp'
202*ab625e41SAndroid Build Coastguard Worker        }, function(version, url) {
203*ab625e41SAndroid Build Coastguard Worker          $('.version').text(version);
204*ab625e41SAndroid Build Coastguard Worker          $('.version-tag').text('v' + version);
205*ab625e41SAndroid Build Coastguard Worker          $('.version-href').attr('href', url);
206*ab625e41SAndroid Build Coastguard Worker        });
207*ab625e41SAndroid Build Coastguard Worker      });
208*ab625e41SAndroid Build Coastguard Worker
209*ab625e41SAndroid Build Coastguard Worker      var _gaq = _gaq || [];
210*ab625e41SAndroid Build Coastguard Worker      _gaq.push(['_setAccount', 'UA-40704740-2']);
211*ab625e41SAndroid Build Coastguard Worker      _gaq.push(['_trackPageview']);
212*ab625e41SAndroid Build Coastguard Worker
213*ab625e41SAndroid Build Coastguard Worker      (function() {
214*ab625e41SAndroid Build Coastguard Worker        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
215*ab625e41SAndroid Build Coastguard Worker        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
216*ab625e41SAndroid Build Coastguard Worker        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
217*ab625e41SAndroid Build Coastguard Worker      })();
218*ab625e41SAndroid Build Coastguard Worker    </script>
219*ab625e41SAndroid Build Coastguard Worker  </body>
220*ab625e41SAndroid Build Coastguard Worker</html>
221