DefaultHttpClient execute() 方法報錯,defaulthttpclient
今天寫代碼,這裡報錯
public static String doGet(String url, boolean useCache, String encoding)
throws Exception {
if (TextUtils.isEmpty(url)) {
throw new NullPointerException("網路請求地址不可為空");
}
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.execute(httpGet); //這裡報錯
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;
}
.解決方案很簡單
Manifest資訊清單檔中加上網路通訊協定
<uses-permission android:name="android.permission.INTERNET" />
executequery方法出錯
user是關鍵字,錯誤鳥
在ssh中action execute方法裡的問題 各位大蝦幫幫忙吧,自己試了很多方法,總報錯
方法有很多
1.ActionContext.getContext().getParameters().get("office")
2.其實struts2中 會把所有的值壓倒 valuestacks裡 你只要 在這個action中定義一個private Office office; 屬性 並且封裝下給他一個set get 方法。在前台提交時 後台會自動把前台的值 set到這個office對象裡了。 然後就可以直接操作這個對象了。