c# - How to send an HTTP request and don't process the response -
as service, server needs notify clients resource ready use.
 happen, give me url callback , when resource ready send http request callback url.
what best way initiate http request , don't process response?
var wc = new webclient(); wc.downloadstringasync(new uri(url)); in code example though ignore response completely, server still call thread download response (which couldn't care less...) once it's ready.
i suggest package id: microsoft.net.http , use more modern httpclient library. question of whether 'await' response or not. if dont await fire , forget , achieve wanted behaviour:
using system; using system.net.http; using system.threading.tasks;  namespace consoleapplication1 { public class httphelper {      public static async task waitforresponse()     {         using (var client = new httpclient())         {             httpresponsemessage response = await  client.getasync(new uri("http://google.com"));         }     }      public static async task fireandforget()     {         using (var client = new httpclient())         {             client.getasync(new uri("http://google.com"));         }     } } }
Comments
Post a Comment