This project is read-only.

X-Requested-With and MediaTypeFormatter bypassed

Topics: Web Api
Feb 6, 2012 at 4:29 PM

If the X-RequestedWith header is specified (automatically by $.ajax), my MediaTypeFormatter is not called.
(I easily solved by using the before event and removing that header)

Complete headers. The same request without X-Requested-With works. (I tested it with the test client and fiddler).

GET http://localhost:63352/categories/Condiments?_=1328541806804 HTTP/1.1
Content-Type: image/png
Accept: image/png
X-Requested-With: XMLHttpRequest
Referer: http://localhost:63352/
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: localhost:63352
Connection: Keep-Alive
Cookie: mstcid=57a10f7

Any idea for this behavior? 

Feb 6, 2012 at 4:52 PM

This is a bug in WCF Web API – we aggressively assume that if the request was made using XHR then the response should be JSON. This issue will be fixed in a future release.

Daniel Roth

Feb 6, 2012 at 4:53 PM

Thank you Daniel.