简体   繁体   English

Http标头引发异常C#HttpResponseMessage

[英]Http Header Throws Exception C# HttpResponseMessage

Okay I'm developing a sevice application that runs on Cisco IP Phones. 好的,我正在开发在Cisco IP电话上运行的服务应用程序。 The application involves displaying messages to the phone. 该应用程序涉及向手机显示消息。

I would like to make use of the way CISCO phones use the Expires header in a http Response. 我想利用CISCO电话在http响应中使用Expires标头的方式。 Basically a message i send to the phone will expire when the time specified in the header is reached (expired messages are removed from the message stack). 基本上,当到达标题中指定的时间时,我发送到电话的消息将过期(过期的消息将从消息堆栈中删除)。 The full documentation can be read at this address 完整的文档可以在此地址阅读
http://www.cisco.com/en/US/docs/voice_ip_comm/cuipph/all_models/xsi/3_3_4/english/programming/guide/ip334ch5.html#wp1030621 http://www.cisco.com/zh_CN/docs/voice_ip_comm/cuipph/all_models/xsi/3_3_4/english/programming/guide/ip334ch5.html#wp1030621

In my C# WebService i construct the response using a HttpResponseMessage. 在我的C#WebService中,我使用HttpResponseMessage构造响应。 Before i return my response i add the Expires header using 在返回响应之前,我使用添加Expires标头

 response.Headers.Add("Expires", "-1"); //Immediately expires.

My problem: 我的问题:

The previous line of code throws an InvalidOperationException with the message Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage 上一行代码将InvalidOperationException与消息一起抛出确保请求标头用于HttpRequestMessage,响应标头与HttpResponseMessage

I believe that the HttpResponseMessage is performing some validation and that Expires is not a valid response header. 我相信HttpResponseMessage正在执行一些验证,并且Expires不是有效的响应头。 But its what the CISCO stuff requires. 但这正是CISCO所需的东西。

Can i force this key value into the header even though its not strictly correct HTTP 即使不是严格正确的HTTP,我也可以强制将此键值放入标头中

Expires标头位于Content对象上。

response.Content.Headers.Expires = new DateTimeOffset(DateTime.UtcNow.Add(new TimeSpan(0,0,0,5)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM