'Is there any way to send cookies using Blazor WebAssembly?
public static async Task<T> GetDataFromWebServiceWithCookies<T>(string serviceName, string methodName, Dictionary<string, object> parameters)
{
HttpResponseMessage httpResponseMessage;
string httpResponseMessageData = "";
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "ServiceModule/" + serviceName + "/" + methodName);
byte[] json = JsonSerializer.SerializeToUtf8Bytes(parameters);
httpRequestMessage.Content = new ByteArrayContent(json);
httpResponseMessage = await HttpClient.SendAsync(httpRequestMessage);
if (httpResponseMessage.IsSuccessStatusCode)
{
httpResponseMessageData = await httpResponseMessage.Content.ReadAsStringAsync();
}
return JsonSerializer.Deserialize<T>(httpResponseMessageData);
}
First of all this is my very first post on Stack Overflow, so I hope I am not screwing up. I am using the above code to communicate with a web service using Blazor WASM HttpClient. Everything works fine including setting the call parameters as message content, but I didn't find any way to set cookies in my httpRequestMessage. The .NET classes that can be used for cookie handling like 'CookieContainer', or setting the 'UseCookies' property on a HttpClientHandler are not supported on Blazor WASM applications. Is there any way to send a cookie using Blazor WebAssembly yet? The easiest way would be to just add the cookie as a header to httpRequestMessage, but this doesn't work either.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
