0
我正在處理Volley POST請求,並在單獨的線程中運行該文章。我看到的問題是,即使設置了超時值,RequestFuture也會立即超時(小於一秒)。有人可以幫忙嗎?服務器URL是可訪問的,它返回200 OK,但RequestFuture get不會等待服務器響應。 錯誤:java.util.concurrent.ExecutionException:com.android.volley.TimeoutError排球網絡總是超時
Thread t = new Thread(new Runnable() {
@Override
public void run() {
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, jsonBody, future, future);
RequestQueue queue = Volley.newRequestQueue(context);
queue.add(request);
try {
JSONObject response = future.get(50, TimeUnit.SECONDS);
if(response != null) {
DialogUtility.alert(context, response.toString());
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
});
t.start();