DefaultHttpClient execute () method error, defaulthttpclient
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 httpGet = new HttpGet (url );
If (! LFormat. isEmpty (LApplication. getInstance (). getSessionValue ())){
HttpGet. setHeader (LApplication. getInstance (). getSessionKey (),
LApplication. getInstance (). getSessionValue ());
}
HttpResponse httpResponse;
HttpResponse = httpClient.exe cute (httpGet); // an error is returned here.
HttpEntity httpEntity = httpResponse. getEntity ();
If (httpResponse. getStatusLine (). getStatusCode () = 200 ){
InputStream 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"/>
Executequery method error
User is a keyword, error bird
In ssh, the action execute method may be of any help. I tried many methods and always reported an error.
There are many methods
1. ActionContext. getContext (). getParameters (). get ("office ")
2. In fact, in struts2, all the values will overwhelm valuestacks. You only need to define a private Office office in this action; and encapsulate the property and give it a set get method. When the front-end is submitted, the background will automatically set the front-end value to this office object. Then you can directly operate on this object.