无法使用Closure库将标头Content-Type更改为application / json。这个xhr.send()是预检的。我已经在服务器端进行了所需的配置。但不知何故,从客户端,我无法对Content-Type进行更改,它始终保持为null。有没有什么办法可以强制标题改变而不是这个代码?
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]}
答案 0 :(得分:1)
我认为标题应该添加到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);
类似的东西对我们来说很好......
此致
雷