在我的应用中,我使用WebView
。我试图调用无法继续执行请求的POST方法。我收到此错误:
XMLHttpRequest无法加载https:// ***** / support / create_ticket。 请求标头字段不允许使用Content-Type 访问控制允许报头。 at null:1
它只在装有Jelley bean 4.2.2的设备中发生,在其他所有操作系统中都可以正常工作。
非常感谢你的帮助。
答案 0 :(得分:0)
将此添加到请求标题:
Map<String, String> extraHeaders=new HashMap<>();
extraHeaders.put("Access-Control-Allow-Origin","*");
extraHeaders.put("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");
您可能还需要添加它:
extraHeaders.put("Access-Control-Allow-Methods","POST");//you add more:"GET, POST, PUT"
---根据您的代码更新,以下是调整:
RestAPI.Groups = $resource('groups/:id', {
id: '@id'
}, {
get: {
method: "GET",
KalseferPrivateAPI: true,
interceptor: Interceptors.get
},
join: method: "POST",
KalseferPrivateAPI: true,
interceptor: Interceptors.post,
headers: {
'Access-Control-Allow-Origin:*',
'Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept',
'Access-Control-Allow-Methods:POST'
},
url: 'groups/join'
}, addMember: {
method: "POST",
KalseferPrivateAPI: true,
interceptor: Interceptors.post,
headers: {
'Access-Control-Allow-Origin:*',
'Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept',
'Access-Control-Allow-Methods:POST'
},
url: 'groups/:id/users/:users',
params: {
id: '@id',
users: '@users'
}
}
});
我希望这可能有所帮助,&#39;。