问题描述
当我在下面的代码中添加expires标头时,它将引发异常。
public HttpResponseMessage CreateResponse<T>(HttpRequestMessage httpRequestMessage,HttpStatusCode httpStatusCode,T responseObject)
{
HttpResponseMessage Response = httpRequestMessage.CreateResponse(httpStatusCode,responseObject);
try
{
Response.Headers.Add("Cache-Control","no-cache,no-store,must-revalidate");
Response.Headers.Add("Pragma","no-cache");
Response.Headers.Add("Expires","0");
}
catch (Exception ex)
{
//Logger("Exception while adding the response headers. " + ex.Message);
}
return Response;
}
例外:
System.InvalidOperationException: Misused header name. Make sure request headers are used with HttpRequestMessage,response headers with HttpResponseMessage,and content headers with HttpContent objects.
at System.Net.Http.Headers.HttpHeaders.CheckHeaderName(String name)
at System.Net.Http.Headers.HttpHeaders.Add(String name,String value)
at CheckStatusApi.APIControllersV1.NoCacheApiController.CreateResponse[T](HttpRequestMessage httpRequestMessage,T responseObject)
我显然是将其与HttpResponseMessage
配合使用,所以我看不出问题所在。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)