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