gpt4 book ai didi

c# - 在 HttpWebRequest 上调用 Abort 是否对 responseStream.BeginRead 有任何影响

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:43 26 4
gpt4 key购买 nike

来自 MSDN:

"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."

但是如果 responseStream.BeginRead 正在进行中,Abort 会取消这次读取吗?

最佳答案

是的,它正在影响从流中读取。我已经测试了在 msdn HttpWebRequest.Abort Method 中使用的示例代码,并且调用 EndReadReadCallBack 函数中抛出异常。

RequestState myRequestState = (RequestState)asyncResult.AsyncState;
Stream responseStream = myRequestState.streamResponse;
int read = responseStream.EndRead(asyncResult);

ReadCallBack Exception raised!

Message:The request was aborted: The request was canceled.

Status:RequestCanceled Press any key to continue..........

关于c# - 在 HttpWebRequest 上调用 Abort 是否对 responseStream.BeginRead 有任何影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6843414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com