问题
Here are the request headers from postman to my asp.net_core 2.0 API.
- Content-Type: application/json
- Accept: application/json
Response from my asp.net core application is an exception thrown in a string format. But the below response headers have been sent from the API to postman.
Cache-Control : no-cache, no-store, must-revalidate Pragma : no-cache Transfer-Encoding : chunked Content-Type : application/json; charset=utf-8 Age : 0 Server : Kestrel
Since the Request body is a string , and the Content-Type is set as application/json. Client is unable to parse it. I have added the below code in my API middleware startup class configure() method to disable Headers cache. But since the "Accept" header is application/json, the response header "content-type" is also set to application/json instead of text/plain . Please let me know what additional things have to be done to change the response header content-type to text/plain.
app.Use(
next =>
{
return async context =>
{
context.Response.OnStarting(
() =>
{
context.Response.Headers.Add("Cache-Control", "no-cache, no-store,
must-revalidate");
context.Response.Headers.Add("Pragma", "no-cache");
context.Response.Headers.Add("Age", "0");
return Task.CompletedTask;
});
await next(context);
};
});
Thanks in advance .
来源:https://stackoverflow.com/questions/54898603/asp-net-core-headers-caching-issue