views:

77

answers:

1

I've got a Silverlight app that talks to a REST web service using the WebClient class. It runs fine in IE 8 and Chrome 5, but the web service call fails in Firefox 3.

I've narrowed down the problem: Firefox 3 is changing the Accept header of my HTTP request. here's my simplified code:

// 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);

Using Fiddler to investigate the data on the pipes, the request has its header replaced:

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

Notice the 2nd line, "Accept" -- it's been replaced with text/html, xml, and other formats. Not what I'm looking for -- I absolutely need JSON coming back.

Is there a way to prevent Firefox from modifying my Accept header?

A: 

Turns out the Accept header is being overwritten in all browsers. IE and Chrome overwrite the Accept header with the value of "*/*" (star slash star). Firefox overwrites it with some strange value that specifies XML, among other things.

The answer to this problem is you cannot expect to have your Accept header preserved. The browser will overwrite the Accept header, even if you use ClientHttp.

Judah Himango