DefaultHttpClient execute () method error, defaulthttpclient

Source: Internet
Author: User

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.

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.