/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

  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>
  33. The API for client-side HTTP communication.
  34. <p/>
  35. The usual execution flow can be demonstrated by the
  36. code snippet below:
  37. <PRE>
  38. HttpClient httpclient = new DefaultHttpClient();
  39. // Prepare a request object
  40. HttpGet httpget = new HttpGet("http://www.apache.org/");
  41. // Execute the request
  42. HttpResponse response = httpclient.execute(httpget);
  43. // Examine the response status
  44. System.out.println(response.getStatusLine());
  45. // Get hold of the response entity
  46. HttpEntity entity = response.getEntity();
  47. // If the response does not enclose an entity, there is no need
  48. // to worry about connection release
  49. if (entity != null) {
  50. InputStream instream = entity.getContent();
  51. try {
  52. BufferedReader reader = new BufferedReader(
  53. new InputStreamReader(instream));
  54. // do something useful with the response
  55. System.out.println(reader.readLine());
  56. } catch (IOException ex) {
  57. // In case of an IOException the connection will be released
  58. // back to the connection manager automatically
  59. throw ex;
  60. } catch (RuntimeException ex) {
  61. // In case of an unexpected exception you may want to abort
  62. // the HTTP request in order to shut down the underlying
  63. // connection and release it back to the connection manager.
  64. httpget.abort();
  65. throw ex;
  66. } finally {
  67. // Closing the input stream will trigger connection release
  68. instream.close();
  69. }
  70. }
  71. </PRE>
  72. </body>
  73. </html>