Onur Gumus
Onur Gumus

Reputation: 1439

How to abort an HTTP Request from .NET?

When I use fiddler I am able to abort an http request by right clicking to the request and selecting abort session option. I can confirm this from the server side (I ran ASP.NET Web API) that the client is effectively disconnected. Now I am trying to mimic the same behavior from a .NET client.

So far I tried things like, System.Net.Http.HttpClient.CancelPendingRequests or System.Net.HttpWebRequest.Abort. However no matter I tried, from fiddler I observe that, despite I am making above calls, the request keeps running and returns a response. In other words, these calls do not cause anything that causes server detecting a disconnect. Is there a way to achieve what I want ?

Upvotes: 1

Views: 2602

Answers (1)

usr
usr

Reputation: 171178

I believe the .NET cancel worked but Fiddler continues making the request. Fiddler is not just an observer. It is a man in the middle. It terminates your connection and initiates its own to the server.

You can try this out by making some browser requests and killing the browser process. If Fiddler does not show any kind of message or error then this means that Fiddler simply ignores killed client connections.

You also can test this using Wireshark.

So you don't seem to have a problem. This should work.

Upvotes: 3

Related Questions