PageRenderTime 44ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/src/org/apache/http/client/package.html

http://github.com/onedanshow/Screen-Courter
HTML | 89 lines | 45 code | 16 blank | 28 comment | 0 complexity | 1a1e837494bf01ae720d41e245924263 MD5 | raw file
Possible License(s): GPL-3.0
 1<html>
 2<head>
 3<!--
 4/*
 5 * ====================================================================
 6 * Licensed to the Apache Software Foundation (ASF) under one
 7 * or more contributor license agreements.  See the NOTICE file
 8 * distributed with this work for additional information
 9 * regarding copyright ownership.  The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License.  You may obtain a copy of the License at
13 *
14 *   http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied.  See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 * ====================================================================
23 *
24 * This software consists of voluntary contributions made by many
25 * individuals on behalf of the Apache Software Foundation.  For more
26 * information on the Apache Software Foundation, please see
27 * <http://www.apache.org/>.
28 *
29 */
30-->
31</head>
32<body>
33The API for client-side HTTP communication.
34<p/>
35The usual execution flow can be demonstrated by the
36code snippet below:
37
38<PRE>
39HttpClient httpclient = new DefaultHttpClient();
40
41// Prepare a request object
42HttpGet httpget = new HttpGet("http://www.apache.org/");
43
44// Execute the request
45HttpResponse response = httpclient.execute(httpget);
46
47// Examine the response status
48System.out.println(response.getStatusLine());
49
50// Get hold of the response entity
51HttpEntity entity = response.getEntity();
52
53// If the response does not enclose an entity, there is no need
54// to worry about connection release
55if (entity != null) {
56    InputStream instream = entity.getContent();
57    try {
58
59        BufferedReader reader = new BufferedReader(
60                new InputStreamReader(instream));
61        // do something useful with the response
62        System.out.println(reader.readLine());
63
64    } catch (IOException ex) {
65
66        // In case of an IOException the connection will be released
67        // back to the connection manager automatically
68        throw ex;
69
70    } catch (RuntimeException ex) {
71
72        // In case of an unexpected exception you may want to abort
73        // the HTTP request in order to shut down the underlying
74        // connection and release it back to the connection manager.
75        httpget.abort();
76        throw ex;
77
78    } finally {
79
80        // Closing the input stream will trigger connection release
81        instream.close();
82
83    }
84}
85
86</PRE>
87
88</body>
89</html>