我试图通过axios从我的react native应用程序使用http调用我的本地laravel API:
login: (email, password) => {
axios
.post('http://booking-api.valet/login', {
email: email,
password: password,
device_name: 'iphone',
})
.then(response => {
const userResponse = {
email: response.data.user.email,
token: response.data.token,
};
setUser(userResponse);
AsyncStorage.setItem('user', JSON.stringify(userResponse));
})
.catch(error => {
console.log(error.response);
setErrors(JSON.stringify(error.response.data));
});
},
字符串
API正在代客提供,不安全
的数据
当我试图通过http向这个端点发出请求时,我得到了这个axios错误:
The certificate for this server is invalid. You might be connecting to a server that is pretending to be “booking-api.valet” which could put your confidential information at risk.
型
经过研究,我发现我可以将这个键设置为true,一切都会好起来:
的
然而,情况并非如此,即使在删除ios build文件夹并重新启动应用程序后,
我也试过保护代客项目,并使用https发出请求,但它仍然无法工作
2条答案
按热度按时间4dbbbstv1#
已解决
Noman是正确的,我发现我的本地Laravel代客后端重定向我使用HTTPS,即使我特别解除了该项目的安全保护(如我的问题的第一个截图所示)
我尝试了不同的方法来阻止这种情况发生,例如取消链接项目并再次链接(然后再次使用
valet unsecure *project-name*
取消安全性),但Chrome一直重定向到https最后,我很懒,只是创建了一个新的laravel项目,并将其与valet链接(使用http时自动不安全)。
h22fl7wq2#
我也遇到了React Native和Laravel Valet一起工作的问题。我的解决方法是使用Laravel Artisan的serve命令,并将我的React Native应用指向serve端点:
字符串