【发布时间】:2019-02-27 21:06:46
【问题描述】:
我一直在尝试使用带有基本身份验证的 axios,但它总是返回 not found。
这是我的代码
const ROOT_URL='http://localhost/b2b_ecom/b2b-api/index.php/api/';
export function login () {
return function(dispatch)
{
const api = axios.create({
mode: 'no-cors',
credentials:'include',
redirect: 'follow',
auth: {
username: 'mouad@b2b.dz',
password: '123456'
},
headers: {
'Content-Type': 'application/json',
}
});
api.post(`${ROOT_URL}site/login `).then(function(response)
{
dispatch({LOGIN,payload:response.data});
return true;
}).catch(function(error)
{
return error;
});
} ;
}
这是我得到的错误:
选项http://localhost/b2b_ecom/b2b-api/index.php/api/site/login 404(未找到)
无法加载http://localhost/b2b_ecom/b2b-api/index.php/api/site/login:预检响应没有 HTTP ok 状态。
【问题讨论】:
-
404 表示您的 PHP 服务器无法在
http://localhost/b2b_ecom/b2b-api/index.php/api/site/login找到资源 我们真的无法解决这个问题。您需要检查网址是否正确。 -
这个问题与JavaScript无关; (如果 URL 中没有拼写错误)您应该描述您使用哪个服务器以及如何配置其路由。还请为您的问题添加适当的标签
-
实际上,我使用的是 Google chrome CROS 扩展。当我禁用它时,错误会发生变化:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'localhost:3030' 不允许访问。 P.S:是的,它与邮递员一起正常工作
标签: authentication axios basic-authentication