Reference: http://stackoverflow.com/questions/2742236/android-httpclient
Source code
First, add the permission in androidmanifest. xml:
<Uses-PermissionAndroid: Name= "Android. Permission. Internet"> </Uses-Permission></Manifest>
Code:
New Thread ( New Runnable (){ Public Void Run () {httpclient = New Defaulthttpclient (); httpget httpget2 = New Httpget ("http://wangkangle.com /" ); Httpresponse response2 = Null ; Try {Response2 = Httpclient.exe cute (httpget2 );} Catch (Clientprotocolexception E1 ){ // Todo auto-generated Catch Block E1.printstacktrace ();} Catch (Ioexception E1 ){ // Todo auto-generated Catch Block E1.printstacktrace ();} httpentity entity = Response2.getentity (); If (Entity! = Null ){ Long Len = Entity. getcontentlength (); If (Len! =-1 ){ Try {String content_baidu = Entityutils. tostring (entity); log. D (TAG, content_baidu );} Catch (Parseexception e ){ // Todo auto-generated Catch Block E. printstacktrace ();} Catch (Org. Apache. http. parseexception e ){ // Todo auto-generated Catch Block E. printstacktrace ();} Catch (Ioexception e ){ // Todo auto-generated Catch Block E. printstacktrace ();}} Else { // Stream content out }}}). Start ();
End