I'm using the ASP.NET WebApi to create a RESTful API. I'm creating a PUT method within one of my controllers, and the code looks like this:
public HttpResponseMessage Put(int idAssessment, int idCaseStudy, string value) {
var response = Request.CreateResponse();
if (!response.Headers.Contains("Content-Type")) {
response.Headers.Add("Content-Type", "text/plain");
}
response.StatusCode = HttpStatusCode.OK;
return response;
}
When I PUT to that location with the browser via AJAX, it gives me this Exception:
Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
But isn't Content-Type
a perfectly valid header for a response? Why am I getting this exception?