我正在尝试在HttpClient.DeleteAsync请求上设置自定义标头。我尝试过使用
document.getElementById("web").innerHTML = favWebComics[x];
但是会收到此错误
httpClient.DefaultRequestHeaders.Add("X-Parse-Application-Id",ParseAppID);
HttpClient.SendAsync可以使用
发送自定义请求标头Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
和HttpClient.PostAsync可以用
发送它们System.Net.Http.HttpRequestMessage.Headers.Add("X-Parse-Application-Id",ParseAppID);
如何使用DeleteAsync执行此操作?
答案 0 :(得分:3)
实例化HttpRequestMessage
并改为使用SendAsync
:
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();
}