0
所以我有一個網頁API設置爲生成一個令牌爲您返回時發送一個用戶名和密碼是相同的,這是通過郵遞員如果你的作品給身體像這樣React Js Axios發佈請求不從網頁api返回機構
這個作品它給你一個令牌和正確的信息,但是當我從瀏覽器,Firefox做,或即它給了我一個錯誤我的代碼是這樣的,
var d = {
username: Uname,
surname: Pword,
grant_type: "password",
client_id: "099153c2625149bc8ecb3e85e03f0022",
};
console.log(d);
var self = this;
return (
axios.post('http://localhost/hydraauth/oauth/token', {
headers: {
'Content-Type': 'application/json',
},
data: d
}).then(function (response) {
console.log(response.data)
self.setState({
isLoggedIn: true,
Uname: Uname,
}, function() {
sessionStorage.setItem("Login", true);
sessionStorage.setItem("Uname", Uname)
window.location.href = "/";
});
}).catch(function (error) {
if (error.response){
console.log(error.response)
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else {
window.alert("Incorrect Username Or Password Or Unauthorized To Access This.")
}
})
);
它給了我這個錯誤在chro我
這裏是錯誤擴大了網絡選項卡的
圖像中鉻的響應選項卡爲空
我想問題是由於[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) –
@BardiaRastin它怎麼可能是Cors當它從郵遞員 –
工作,因爲CORS只存在於瀏覽器... –