2014-10-31 112 views
0

有一個網站使用jquery在另一個域(Utlising CORS)上調用WCF Web服務。大多數方法都是GET方法,但有一些PUT方法。PUT HTTP/400請求Firefox/IE。適用於Chrome/Opera

所有的GET方法在所有瀏覽器上都能正常工作。 PUT方法但是隻適用於Chrome和Opera。對於Firefox和Internet Explorer,它們將導致HTTP 400 BAD REQUEST錯誤。我已經閱讀了所有內容,並試圖改變Web服務的CORS設置,但沒有成功。

如果瀏覽器在某些情況下完美工作而不是爲其他人完成工作,那麼瀏覽器如何進行這些PUT調用?

僅供參考,web服務Global.asax文件看起來像這樣:

protected void Application_BeginRequest(object sender, EventArgs e) 
    { 

     //CORS ENABLED 
     HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); 

     if (HttpContext.Current.Request.HttpMethod == "OPTIONS") 
     { 
      //These headers are handling the "pre-flight" OPTIONS call sent by the browser 
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); 
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Authorization, Origin, Content-Type, Accept, X-Requested-With"); 
      HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000"); 

      HttpContext.Current.Response.End(); 

     } 
    } 

,並在web.config相關的會話是這樣的:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <httpProtocol> 

    </httpProtocol> 
    </system.webServer> 

任何想法?

編輯:這是存在的jQuery請求:

 addAbs = function addAbs() { 
     return $.ajax({ 
      type: 'PUT', 
      url: Constructor.prototype.getServletURL(), 
      contentType: "application/json; charset=utf-8", 
      headers: {"Origin": "http://app-eservices.talentia-software.com"}, 
      data: JSON.stringify(newAbsence), 
      timeout: GlobalContext.xhrTimeout, 
      beforeSend: self.showLoadingDialog('') 
     }); 
+0

我們可以看到你的jQuery AJAX請求嗎? – MightyLampshade 2014-10-31 15:49:21

+0

嗨,我很抱歉,慢回覆,更新線程與jQuery請求 – 2014-11-02 10:33:50

回答

0

原來,原因是AJAX請求中指定的一個的contentType 「字符集= UTF-8」,而不是「字符集= UTF-8 「,所以大寫造成了差異。作爲參考,大寫版本是正確的,但兩者都應該工作。

這對Chrome自動大寫它不是問題,但對於Firefox和其他不改變大小寫的瀏覽器,請求最終會出現HTTP 400錯誤請求錯誤。顯然WCF服務只能接受這個奇怪的大寫版本。除了更改AJAX請求之外,是否有人知道是否有另一種方法讓WCF服務接受小寫版本?