![](/img/trans.png)
[英]How to change the form to Content-Type: application / json
[英]Unable to change header Content-Type to application/json
無法使用Closure庫將標頭Content-Type更改為application / json。 此xhr.send()已預檢。 我已經在服務器端進行了所需的配置。 但是從客戶端以某種方式,我無法更改Content-Type,它始終保持為空。 有什么辦法可以強制標題更改而不是此代碼?
xhr.headers.set( '內容 - 類型', '應用/ 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]}
我認為應該將標頭添加到opt_headers映射中的xhr.send()函數中:
goog.net.XhrIo.prototype.send = function(url,opt_method,opt_content,opt_headers)
所以:
var xhr = new goog.net.XhrIol
var headers = new goog.structs.Map;
headers.set('Content-Type','application/json')
xhr.send(uri, 'OPTIONS', null, headers);
類似的東西對我們來說很好...
問候,
劉若英
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.