DefaultHttpClient execute() 方法報錯,defaulthttpclient

來源:互聯網
上載者:User

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對象裡了。 然後就可以直接操作這個對象了。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.