HTTP Communication httpclient interface for Android Development

Source: Internet
Author: User

HTTP Communication for Android Development

Httpclient Interface

/*

* HTTP Communication httpclient interface developed for Android

*
Beijing Android Club group: 167839253

* Created on: 2012-5-10

* Author: blueeagle

* Email: liujiaxiang@gmail.com

*/

Httpclient Interface

Apache provides the httpclient interface, which encapsulates and abstracts classes in java.net. It is more suitable for developing online applications on Android. To use httpclient, you also need to know some classes:

1.
Clientconnectionmanager Interface

This interface is used by the client to connect to the browser and provides the following Abstract METHODS:

 

Public Methods

Abstract void

Closeexpiredconnections ()// Close all invalid timeout connections

Closes all expired connections in the pool.

Abstract void

Closeidleconnections (long idletime, timeunit tunit)// Close idle connections

Closes idle connections in the pool.

Abstract schemeregistry

Getschemeregistry ()// Get a schemeregistry

Obtains the scheme registry used by this manager.

Abstract void

Releaseconnection (managedclientconnection Conn, long validduration, timeunit)

Releases a connection for use by others. // release a connection

Abstract clientconnectionrequest

Requestconnection (httproute route, object state )//
Request a new connection

Returns a new clientconnectionrequest, from which a managedclientconnection can be obtained or the request can be aborted.

Abstract void

Shutdown ()
// Close the manager and release the resource

Shuts down this Connection Manager and releases allocated resources.

 

 

2.
Defaulthttpclient

Defaulthttpclient is the default HTTP client that can be used to create an HTTP connection.

This class replaces httpclient in httpclient 3.

The code for creating a defaulthttpcolient is as follows:

Httpclient = new defaulthttpclient ();

 

3.
Httpresponse

Httpresponse is an HTTP connection response. After an HTTP connection is executed, an httpresponse is returned. You can obtain some response information through httpresponse. For example, the code that requests an HTTP connection and obtains whether the request is successful:

Httpclient = new defaulthttpclient ();

Httpresponse = httpclient.exe cute (httprequest );

If (httpresponse. getstatusline (). getstatuscode () = httpstatus. SC _ OK ){

// Connection successful

}

 

The get and post code will be attached later. The code is basically similar to the httpurlconnection code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.