我有一个Silverlight应用程序使用WebClient类与REST Web服务对话。它在IE 8和Chrome 5中运行良好,但Firefox 3中的Web服务调用失败。Silverlight WebClient在Firefox中覆盖Accept头3
我已经缩小了问题范围:Firefox 3正在更改我的HTTP请求的Accept标头。这里是我的简化代码:
// Use the ClientHttp stack.
WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
// Call the web service.
var webClient = new WebClient();
webClient.Headers["Accept"] = "application/json";
webClient.DownloadStringAsync(someUrl);
使用招来调查管道中的数据,要求有其标题改为:
GET /1/36497f32-1acd-4f4e-a946-622b3f20dfa5/Content/GetAllTextContentsForUser/0 HTTP/1.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Host: localhost:88
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
通知二号线,“接受” - 它被替换文本/ html,xml和其他格式。不是我在找什么 - 我绝对需要JSON回来。
有没有办法阻止Firefox修改我的Accept头?
OK - 所有浏览器都会替换接受字符串。 IE和Chrome将其替换为“*/*”,而Mozilla引入上面列出的那种时髦的字符串:http://developer.yahoo.com/dotnet/silverlight/2.0/requestheaders.html – 2010-08-04 20:14:44
我希望我的Web服务调用接受JSON,而不是XML,该死。帮帮我! – 2010-08-04 20:15:19