xUtils網絡超時設置configCurrentHttpCacheExpiry和SoTimeout和connectionTimeout的區別

示例代碼:


HttpUtils https = new HttpUtils();
		https.configCurrentHttpCacheExpiry(1000 * 10);// 超時時間 Long配置當前Http緩存到期
		// 設置超時時間
		https.configTimeout(10 * 1000);// 連接超時  //指的是連接一個url的連接等待時間。
		https.configSoTimeout(10 * 1000);// 獲取數據超時  //指的是連接上一個url,獲取response的返回等待時間
		RequestParams params = new RequestParams();
		params.addBodyParameter(new BasicNameValuePair("d", did));
		params.addBodyParameter(new BasicNameValuePair("e", e));
		https.send(HttpRequest.HttpMethod.POST,
				MyApp.getInstance().SENDDID_URL, params,
				new RequestCallBack<String>() {
					@Override
					public void onStart() {
						Log.e("Start", "conn...");
					}

					@Override
					public void onLoading(long total, long current,
							boolean isUploading) {
						if (isUploading) {
							Log.e("Loading", "upload: " + current + "/" + total);
						} else {
							Log.e("Loading", "reply: " + current + "/" + total);
						}
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// TODO Auto-generated method stub
						Log.e("error", error.getExceptionCode() + ":" + msg);
						
					}

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						// TODO Auto-generated method stub
						UpdateResponse response = new Gson().fromJson(
								responseInfo.result, UpdateResponse.class);
						String code = response.getEc().trim();
						String msg = response.getEm();
						Log.e("getTrust3", code + "==" + msg + "=jsonString:"
								+ responseInfo.result);
						if (code.equals("0")) {
							
						} else {
							
						}
					}
				});




簡單總結爲:連接時間超時connectionTimeout和讀取數據超時soTimeout
我使用的場景是在android的開源框架Xutils中使用的


http.configTimeout(XXXX) 

http.configSoTimeout(XXXX)

https.configCurrentHttpCacheExpiry(1000 * 10);





發佈了67 篇原創文章 · 獲贊 121 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章