Canceling async httpwebrequests

后端 未结 1 794
暖寄归人
暖寄归人 2021-01-21 07:19

I am making an app that will make several HttpWebRequest objects and downloading my html via the httpRequest.BeginGetResponse method. I get back the IAsyncRe

相关标签:
1条回答
  • 2021-01-21 07:56

    From the documentation for HttpWebRequest.Abort():

    The Abort method cancels a request to a resource. After a request is canceled, calling the GetResponse, BeginGetResponse, EndGetResponse, GetRequestStream, BeginGetRequestStream, or EndGetRequestStream method causes a WebException with the Status property set to RequestCanceled.

    So the behavior you describe is by design. I think you'll have to catch the exception, or else find some way of determining whether Abort was called before calling GetResponse, BeginGetResponse, EndGetResponse, GetRequestStream, BeginGetRequestStream, or EndGetRequestStream.

    0 讨论(0)
提交回复
热议问题