I'm trying to set custom headers on a HttpClient.DeleteAsync request. I've tried using
httpClient.DefaultRequestHeaders.Add("X-Parse-Application-Id",ParseAppID);
but get this error
Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
HttpClient.SendAsync can send custom request headers with
System.Net.Http.HttpRequestMessage.Headers.Add("X-Parse-Application-Id",ParseAppID);
and HttpClient.PostAsync can send them with
System.Net.Http.StringContent.Headers.Add("X-Parse-Application-Id",ParseAppID);
How can I do this with DeleteAsync?
Instantiate an HttpRequestMessage
and use SendAsync
instead:
var request = new HttpRequestMessage(HttpMethod.Delete, requestUri);
request.Headers.Add("X-Parse-Application-Id", ParseAppID);
using (var response = await _calendarClient.SendAsync(request).ConfigureAwait(false))
{
if (response.StatusCode.Equals(HttpStatusCode.NotFound))
{
return;
}
response.EnsureSuccessStatusCode();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With