Http Header Throws Exception C# HttpResponseMessage

609 Views Asked by At

Okay I'm developing a sevice application that runs on Cisco IP Phones. 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. 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

In my C# WebService i construct the response using a HttpResponseMessage. Before i return my response i add the Expires header using

 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

I believe that the HttpResponseMessage is performing some validation and that Expires is not a valid response header. But its what the CISCO stuff requires.

Can i force this key value into the header even though its not strictly correct HTTP

1

There are 1 best solutions below

0
On

The Expires header is on the Content object.

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