如何在 Windows Phone 7 中的 WebRequest 上设置 http 标头 If-Modified-Since? [英] How to set http header If-Modified-Since on a WebRequest in Windows Phone 7?

查看:18
本文介绍了如何在 Windows Phone 7 中的 WebRequest 上设置 http 标头 If-Modified-Since?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 wp7 中设置If-Modified-Since"标头:

Trying to set the 'If-Modified-Since' header in wp7:

request.Headers[HttpRequestHeader.IfModifiedSince] = dateString;

给出错误:

必须使用适当的属性修改此标题.

这意味着应该在请求类上使用属性 .IsModifiedSince,如 MSDN 中所述:http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.ifmodifiedsince.aspx

Which means that the property .IsModifiedSince should be used on the request class, as described in MSDN: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.ifmodifiedsince.aspx

但 Silverlight 即 WP7 中不存在此属性.

But this property does not exist in Silverlight i.e. WP7.

有没有人能够在 Windows Phone 7 上为 http 请求设置这个标头?

Shawn Wildermuth 在 2010 年 9 月发布了这个问题,但没有解决方案:http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/8aec7481-2cf3-4047-b0d4-05d4313a9e4c

Shawn Wildermuth posted this problem back in September 2010, with no solution: http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/8aec7481-2cf3-4047-b0d4-05d4313a9e4c

谢谢!

推荐答案

你可以直接使用 HttpRequestHeader.IfModifiedSince 代表的字符串:

You can just use the string that HttpRequestHeader.IfModifiedSince represents:

request.Headers["If-Modified-Since"] = dateString; 

我不得不使用 WP7 没有公开用于设置的辅助方法的许多其他标头来执行此操作.

I've had to do this with a number of other headers which WP7 doesn't expose helper methods for setting.

更新
基于 http://msdn.microsoft.com/en-us/library/8y7x3zz2(v=VS.95).aspx 似乎无法在 WP7 中设置此标头.

Update
Based on the remarks at http://msdn.microsoft.com/en-us/library/8y7x3zz2(v=VS.95).aspx it would appear that it is not possible to set this header in WP7.

作为替代方案,您可以创建自己的代理服务器来处理应用的缓存.

As an alternative you could create your own proxy server to handle the caching for your app.

这篇关于如何在 Windows Phone 7 中的 WebRequest 上设置 http 标头 If-Modified-Since?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆