Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight WebClient接受头在Firefox 3中被覆盖_Silverlight_Http Headers_Webclient - Fatal编程技术网

Silverlight WebClient接受头在Firefox 3中被覆盖

Silverlight WebClient接受头在Firefox 3中被覆盖,silverlight,http-headers,webclient,Silverlight,Http Headers,Webclient,我有一个Silverlight应用程序,它使用WebClient类与REST web服务对话。它在IE 8和Chrome 5中运行良好,但在Firefox 3中web服务调用失败 我已经缩小了问题的范围:Firefox3正在更改HTTP请求的Accept头。以下是我的简化代码: // Use the ClientHttp stack. WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp); // Call the

我有一个Silverlight应用程序,它使用WebClient类与REST web服务对话。它在IE 8和Chrome 5中运行良好,但在Firefox 3中web服务调用失败

我已经缩小了问题的范围:Firefox3正在更改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);
使用Fiddler调查管道上的数据,请求的头被替换:

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
请注意第二行“Accept”——它已被text/html、xml和其他格式替换。不是我要找的——我绝对需要JSON回来


有没有办法防止Firefox修改我的Accept头?

结果显示,所有浏览器都覆盖了Accept头。IE和Chrome用“*/*”(星形斜杠)的值覆盖Accept标头。Firefox用一些奇怪的值来覆盖它,这些值指定了XML等


这个问题的答案是,您不能期望保留Accept头。即使使用ClientHttp,浏览器也会覆盖Accept头。

OK——所有浏览器都会替换Accept字符串。IE和Chrome将其替换为“/”,而Mozilla则加入了上面列出的时髦字符串:我希望我的web服务调用接受JSON,而不是XML,该死的。救命啊!您最终是如何解决这个问题的?并没有真正解决它-您根本无法期望保留您的accept标头。我们通过在服务器端进行补偿并允许不同的接受头来“解决”它,不管Silverlight发送给我们什么。