HttpWebRequest does not include "Pragma: no-cache" header when doing a POST
I'm using an HttpWebRequest that has a CachePolicy of HttpRequestCacheLevel.Reload. When doing a GET the "Pragma: no-cache" header is in the request (as tracked through Fiddler). But when doing the exact same request using a POST then the "Pragma: no-cache" header is not included.
Is there a reason for this? Is it a bug? And is there a workaround?
Thanks.
EDIT: Just to be clearer abou开发者_开发问答t my goal. I want to have my POST request made using HttpWebRequest to include the "Pragma: no-cache" header, regardless of whether it is required or not. I thought setting the HttpWebRequest.CachePolicy to Reload alone would accomplish this. The reason I need this is because the site I'm making the request against does some checks for this header and is expecting it.
HTTP does allow caching of the response to a POST request. From RFC2616, section 9.5;
Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.
This means that if a POST response includes Cache-Control or Expires (or, given a strict reading of section 13, even a validator like Last-Modified or ETag), the response can be used to satisfy future GET requests. 1
Since the POST is not sending a no-cache, the default is the response won't be cached. It only needs to send a cache policy if you want the response of the post to be cacheable.
精彩评论