Android HttpUrl连接断开

Android HttpUrl连接断开,android,httpurlconnection,Android,Httpurlconnection,在我的活动中,我使用httpurl连接调用url。 在网络强度非常低的情况下,我想断开该请求 How can i disconnect an httpurl connection request that is already been sent? 我想在按下后退按钮时取消请求 HttpGet httpGet = new HttpGet(url); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout i

在我的活动中,我使用httpurl连接调用url。
在网络强度非常低的情况下,我想断开该请求

  How can i disconnect an httpurl connection request that is already been sent?
我想在按下后退按钮时取消请求

HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used. 
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT) 
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);

超时基本上适用于慢速连接。在这段时间之后,您的连接将断开

此答案与按下按钮后取消请求无关,它与
HttpURLConnection
完全无关。