Defaulthttpclient execute () method error

Source: Internet
Author: User

Write code today. An error is reported here.


Public static string doget (string URL, Boolean usecache, string encoding)
Throws exception {
If (textutils. isempty (URL )){
Throw new nullpointerexception ("the network request address cannot be blank ");
}
String data = NULL;
If (usecache ){
Data = dogetcache (URL );
If (! Lformat. isempty (data )){
Return data;
}
}
Defaulthttpclient httpclient = new defaulthttpclient (getclientparams ());
Httpget = new httpget (URL );
If (! Lformat. isempty (lapplication. getinstance (). getsessionvalue ())){
Httpget. setheader (lapplication. getinstance (). getsessionkey (),
Lapplication. getinstance (). getsessionvalue ());
}
Httpresponse;
Httpresponse = httpclient.exe cute (httpget); // an error is returned here.
Httpentity = httpresponse. getentity ();
If (httpresponse. getstatusline (). getstatuscode () = 200 ){
Inputstream = httpentity. getcontent ();
Data = convertstreamtostring (inputstream, encoding );
If (lformat. isempty (data ))
Throw new connectexception (runtime_exception );
Data = lformat. jsontokener (data );
List <cookie> cookies = httpclient. getcookiestore (). getcookies ();
For (INT I = 0; I <cookies. Size (); I ++ ){
If (lapplication. getinstance (). getsessionkey ()
. Equals (cookies. Get (I). getname ())){
Lapplication. getinstance (). setsessionvalue (
Cookies. Get (I). getvalue ());
}
}
} Else {
Throw new connectexception (runtime_exception );
}
If (usecache &&! Lformat. isequal (send_error, data )){
Dosetcache (URL, data );
}
Return data;
}



. The solution is simple.


Add the network protocol to the manifest File


<Uses-Permission Android: Name = "android. Permission. Internet"/>

Defaulthttpclient execute () method error

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.