無法使用Closure庫將頭Content-Type更改爲application/json。這個xhr.send()是預檢的。我已經在服務器端進行了必要的配置。但不知何故,從客戶端,我無法對Content-Type進行更改,它始終保持爲空。有什麼辦法可以強制標題改變比這個代碼?無法將頭Content-Type更改爲應用程序/ json
xhr.headers.set('Content-Type','application/json');
Http-Method: OPTIONS
Content-Type:
Headers: {Accept=[*/*], Accept-Charset=[ISO-8859-1,utf-8;q=0.7,*;q=0.3], accept-encoding=[gzip,deflate,sdch], Accept-Language=[en-US,en;q=0.8], Access-Control-Request-Headers=[origin, content-type], Access-Control-Request-Method=[POST], connection=[keep-alive], Content-Type=[null], Host=[localhost:8181], Origin=[http://localhost], Referer=[http://localhost/?], User-Agent=[Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/12.04 Chromium/18.0.1025.168 Chrome/18.0.1025.168 Safari/535.19]}
Response-Code: 200
Content-Type: text/xml
Headers: {Allow=[POST, GET, OPTIONS, HEAD], Date=[Wed, 11 Jul 2012 16:31:04 GMT], Content-Length=[0]}
一個HTTP'OPTIONS'請求不一般都有內容主體,因此通常不需要內容類型。你是否試圖指定* response *應該在的格式,還是你試圖設置* request *的內容類型? – Gareth 2012-07-11 17:25:09
不應該是你xhr.setRequestHeader(「」,「」);? – albertjan 2012-07-11 17:32:01
感謝您的回覆。 @Gareth我正在嘗試設置請求的內容類型。 – Eddie 2012-07-11 18:05:10