public class UrlVarificationTask extends AsyncTask<Void, Void, Integer> {
private String url;
private UrlVarificationDelegate delegate;
private HttpURLConnection huc;
public UrlVarificationTask(String url, UrlVarificationDelegate delegate) {
this.url = url;
this.delegate = delegate;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Integer doInBackground(Void... params) {
int responseCode = 0;
try {
System.setProperty("http.keepAlive", "false");
URL u = new URL(url);
huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("HEAD");
huc.connect();
responseCode = huc.getResponseCode();
} catch (MalformedURLException mal) {
responseCode = -555;
} catch (IOException io) {
responseCode = -444;
} catch (Exception ex) {
responseCode = -333;
ex.printStackTrace();
}
if (huc != null) {
try {
huc.getInputStream().close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
huc.disconnect();
}
Logger.debug("Response Code==" + responseCode);
return responseCode;
}
@Override
protected void onPostExecute(Integer responseCode) {
delegate.urlVarificationResponseCode(responseCode);
super.onPostExecute(responseCode);
}
}
मैं url सत्यापित के लिए dode ऊपर का इस्तेमाल किया,URL के सत्यापन ठीक काम करता है, लेकिन कनेक्शन रखने के लिए और किसी भी आगे अनुरोध
प्रतिबंधित करता है, तो HEAD मुझे जवाब कोड 200 दे उसके बाद ही मैं वेबव्यू करने के लिए एक यूआरएल को खोलने के।
लेकिन एक बार जब मैं इसे कॉल करता हूं तो यह कनेक्शन रखता है और किसी भी अन्य http अनुरोध को बंद करने के बाद भी अनुमति नहीं देता है, क्या करना है?