How to set headers for DeleteAsync

I am trying to set my own headers in an HttpClient.DeleteAsync request. I 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 using

 System.Net.Http.HttpRequestMessage.Headers.Add("X-Parse-Application-Id",ParseAppID); 

and HttpClient.PostAsync can send them using

 System.Net.Http.StringContent.Headers.Add("X-Parse-Application-Id",ParseAppID); 

How to do it with DeleteAsync?

+7
c # async-await
source share
1 answer

Create an instance of 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(); } 
+1
source share

All Articles