Cancel an HttpClient request

雨燕双飞 提交于 2019-12-19 05:14:44

问题


I am making a simple request for a file using HttpClient from the Apache Commons. Here is my current code:

    httpclient = new DefaultHttpClient();
    httpget = new HttpGet(location);
    context = new BasicHttpContext();
    response = httpclient.execute(httpget, context);
    entity = response.getEntity();

What would I need to do to cancel this request in the middle of the download?


回答1:


You can use httpget.abort() method to abort the request mid way.

See example here



来源:https://stackoverflow.com/questions/5400258/cancel-an-httpclient-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!