1

I'd like to know if I can send an HttpWebRequest without waiting for a response (using .NET).

I am interested in SENDING information, but I don't care about the response.

Do I HAVE to wait for the response? Or I'm safe to just issue the request?

I guess it's the same question as:

How to send http request in asp.net without waiting for a response and without tying up resources

Thanks in advance.

Community
  • 1
  • 1
  • Is there a reason http://stackoverflow.com/questions/449506/how-to-send-http-request-in-asp-net-without-waiting-for-a-response-and-without-ty does not answer your question? – Andrew Hare Jan 18 '09 at 19:05
  • It doesn't answer. It proposes an async solution. I'd like to know if I can just IGNORE the response. What do you think? –  Jan 18 '09 at 19:09
  • 1
    Well, an async solution without a callback is effectively ignoring the response – Andrew Hare Jan 18 '09 at 19:26
  • 1
    Why are you so afraid of an asynchronous solution? Wouldn't this by definition need to be on a separate thread? Remember this is a TCP connection, so you do essentially have to wait for a response before you can send your request. – Shawn Jan 18 '09 at 19:27
  • @Update: Your correct although I don't understand what you mean by waiting for response before sending a request. In HTTP parlance a Request elicits a response not the other way around. – AnthonyWJones Jan 18 '09 at 19:30
  • I am not sure, but I think that it goes like this since it's using TCP: you send out a message to the server saying you are going to send a message, the server returns ok, give me the request, and then you send the request, at which point the server gives its response. – Shawn Jan 18 '09 at 19:36

4 Answers4

2

No you can't just ignore it, in order to ensure the server processes the request you need to ensure something is listening for a response.

The async solution in the other question is the answer. As others have said surely there must be some degree of interest in the request?

Community
  • 1
  • 1
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
1

I guess this depends on what you value - and how the response affects that. Do you care what the response might contain? Do you care whether the user knows about the result? Do you care whether you application's functions are working at all?

If you don't care, at all, about the results of the outgoing messages, then it seems that you can ignore the results.

Argalatyr
  • 4,639
  • 3
  • 36
  • 62
0

The behavior depends upon the server logic for processing the request. For e.g., in ASP.NET if you are processing a long request you have the option to check Request.IsClientConnected periodically to ensure that the client is connected and waiting for the response. You can decide to terminate the processing if the client has disconnected. This helps in saving precious server resources for long running requests.

If you control the server then you should be fine with sending the request and terminating without waiting for response. If the server is not yours, you may try doing trial and error to figure out the server behavior.

PS: I assume you don't care about any server errors upon your request. If you need to ensure that your request succeeded, you'll have to wait for the response.

Shiva
  • 18,235
  • 4
  • 20
  • 9
-1

Well, aren't you interested in whether your request has been received on the server?

If you don't even care about that, it seems like you don't need to send anything in the first place.

Why don't you care about the response? (Or rather, why do you think you don't care about the response?)

jalf
  • 243,077
  • 51
  • 345
  • 550