我正在尝试从oauth2 redirect ui
收到的授权代码中获取访问令牌$.ajax({
dataType: "json",
url:searchurl,
data: {code:code, client_id:'clientid', client_secret:'secret', redirect_uri:'http://localhost:8085/mypro/getAccesstoken.jsp', grant_type:'authorization_code'},
type:"POST",
contentType:"application/x-www-form-urlencoded; charset=utf-8",
crossDomain:true,
cache : true,
success:function(data) {
alert(data);
},
error: function(jqXHR, exception, errorstr) {
console.log(jqXHR);
alert(errorstr);
}
});
网址得到200 OK响应,但我根本没有得到回复
控制台出错:
Object { readyState=0, status=0, statusText="error", more...}
当我尝试设置请求标头Access-Control-Allow-Origin:*
时beforeSend: function(xhr){xhr.setRequestHeader('Access-Control-Allow-Origin', '*');},
请求标题:
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Access-Control-Request-He... access-control-allow-origin
Access-Control-Request-Me... POST
Cache-Control no-cache
Connection keep-alive
Host accounts.google.com
Origin http://localhost:8085
Pragma no-cache
User-Agent Mozilla/5.0 (Windows NT 6.2; rv:25.0) Gecko/20100101 Firefox/25.0
我收到错误
"NetworkError: 405 Method Not Allowed - https://accounts.google.com/o/oauth2/token"