HttpClient.Send not supported in mac

Dani_S 3,086 Reputation points
2024-06-17T12:39:02.6033333+00:00

Hi,

HttpClient.Send(request. HttpCompletionOption.ResponseHeaderRead) => not supported in mac

why? it work on windows.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,066 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 50,106 Reputation points
    2024-06-18T21:10:23.4466667+00:00

    You're trying to use the sync version of the method. Sync methods, in general, are not recommended. For Mac you must use the async version (SendAsync).

    //HttpResponseMessage httpResponse = _client.Send(request, HttpCompletionOption.ResponseHeadersRead); 
    HttpResponseMessage httpResponse = await _client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
    

    You can read more here about why this decision was made but honestly nobody uses Send anyway and you're in the middle of an async all so there is no reason to use the sync version.