You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/06/27 11:29:21 UTC
svn commit: r1354386 - in /httpcomponents/httpclient/trunk/src/site/apt:
index.apt quickstart.apt
Author: olegk
Date: Wed Jun 27 09:29:20 2012
New Revision: 1354386
URL: http://svn.apache.org/viewvc?rev=1354386&view=rev
Log:
HTTPCLIENT-1201: Quick start doc improvements
Contributed by miles zarathustra <albert.bradley at thomsonreuters.com>
Modified:
httpcomponents/httpclient/trunk/src/site/apt/index.apt
httpcomponents/httpclient/trunk/src/site/apt/quickstart.apt
Modified: httpcomponents/httpclient/trunk/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/src/site/apt/index.apt?rev=1354386&r1=1354385&r2=1354386&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/src/site/apt/index.apt (original)
+++ httpcomponents/httpclient/trunk/src/site/apt/index.apt Wed Jun 27 09:29:20 2012
@@ -52,7 +52,7 @@ HttpClient Overview
[[1]] {{{./tutorial/html/index.html}HttpClient Tutorial}} - gives a detailed examination of the
HttpClient API, which was written in close accordance with the (sometimes not very intuitive)
- HTTP specification/standard. A copy is also shipped with the release.
+ HTTP specification/standard. A copy is also shipped with the release.
{{{./tutorial/pdf/httpclient-tutorial.pdf}A PDF version}} is also available
[[1]] {{{./examples.html}HttpClient Examples}} - a set of examples demonstrating some of
Modified: httpcomponents/httpclient/trunk/src/site/apt/quickstart.apt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/src/site/apt/quickstart.apt?rev=1354386&r1=1354385&r2=1354386&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/src/site/apt/quickstart.apt (original)
+++ httpcomponents/httpclient/trunk/src/site/apt/quickstart.apt Wed Jun 27 09:29:20 2012
@@ -52,50 +52,58 @@ HttpClient Quick Start
[]
- [[2]] Quite often the easiest way to get started is with a short example. This example
- shows how to execute HTTP GET and POST requests using HttpClient native API.
+ [[2]] The below code fragment illustrates the execution of HTTP GET and POST requests using the HttpClient native API.
-------------
DefaultHttpClient httpclient = new DefaultHttpClient();
-HttpGet httpget = new HttpGet("http://targethost/homepage");
+HttpGet httpGet = new HttpGet("http://targethost/homepage");
-HttpResponse response1 = httpclient.execute(httpget);
+ HttpResponse response1 = httpclient.execute(httpGet);
// The underlying HTTP connection is still held by the response object
// to allow the response content to be streamed directly from the network socket.
// In order to ensure correct deallocation of system resources
// the user MUST either fully consume the response content or abort request
// execution by calling HttpGet#releaseConnection().
+
try {
System.out.println(response1.getStatusLine());
HttpEntity entity1 = response1.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
EntityUtils.consume(entity1);
-} finally {
- httpget.releaseConnection();
+}
+catch (IOException ex) {
+ // Handle exception
+}
+finally {
+ httpGet.releaseConnection();
}
-HttpPost httpost = new HttpPost("http://targethost/login");
+HttpPost httpPost = new HttpPost("http://targethost/login");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username", "vip"));
nvps.add(new BasicNameValuePair("password", "secret"));
-httpost.setEntity(new UrlEncodedFormEntity(nvps));
-HttpResponse response2 = httpclient.execute(httpost);
+httpPost.setEntity(new UrlEncodedFormEntity(nvps));
+HttpResponse response2 = httpclient.execute(httpPost);
+
try {
System.out.println(response2.getStatusLine());
HttpEntity entity2 = response2.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
EntityUtils.consume(entity2);
-} finally {
- httpost.releaseConnection();
+}
+catch (IOException ex) {
+ // Handle exception
+finally {
+ httpPost.releaseConnection();
}
-------------
- [[3]] The same requests can be executed using a simpler, albeit less felxible, fluent API.
+ [[3]] The same requests can be executed using a simpler, albeit less flexible, fluent API.
-------------