因此,我創建了一個使用CORS與.NET MVC Sidecar項目進行通信的應用程序。除了在POST請求失敗的IE9中,一切都很好。我有一個library它允許GETs工作,但POST請求仍然有問題。看來IE9會去掉contentType
標題。服務器最終將其解釋爲appplication/octet-stream
,而不是text/plain
,這正是我所瞭解的實際情況。CORS在IE9中失敗
裏面我WebAPIConfig.cs的,我有以下功能(由Register
叫):
private static void RegisterFormatters(HttpConfiguration config)
{
// enable browser viewing + jsonp
config.Formatters.Add(new BrowserJsonFormatter());
config.Formatters.Add(new JsonpMediaTypeFormatter(new BrowserJsonFormatter()));
// prettify json: indented + camel case
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.Formatting = Formatting.Indented;
json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
// Tell the formatter to accept text/plain
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain"));
// When we use CORS on IE9, it strips off the content type. The server assigns it application/octet-stream
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/octet-stream"));
}
然而,提琴手仍然告訴我,請求不具有的contentType,並且服務器無法處理application/octet-stream
的contentType。
有沒有人得到這個工作?
F12工具告訴你什麼?同樣的,我從來不信任IE9工具以外的任何信息,然後你仍然不能相信他們會告訴你所有事情。如果你需要虛擬機,請訪問http://modern.ie –