I have the following code to send an HTTP request, but it does not transmit any packets (checked using Wireshark).
var httpClient = new HttpClient();
string uri = "http://" + IP + ":" + port + "/";
var stringContent = new StringContent(xmlString, Encoding.UTF8, "application/xml");
var respone = httpClient.PutAsync(uri, stringContent);
However, it transmits packet when I add:
respone.Wait(100);
Can you please help on how do get httpClient.PutAsync to work without the wait?
Thanks!
PutAsync
is an async method that returnsSystem.Threading.Tasks.Task<TResult>
that is awaitable and should be awaited to call it asynchronous and get the result of it this code is the best way to call the method asynchronously and return its value NOTE: you better call it inAsync
method:if you insist on calling it synchronously, you can get the
Result
ofTask
,