【发布时间】:2021-03-07 23:37:53
【问题描述】:
我在域中有一个网页应用程序:sxxxcex-cxxfc.web.app
我将从其使用 API 的服务器位于 xx.x2.xx.74:8000
要使用 Axios 登录,我执行以下操作:
const url='xx.x2.xx.74:8000/login/'
axios.get(url+user+"/"+password)
.then((res: { data: any; }) => {
setIngresar(false);
const resquest = res.data;
if(resquest=="invalid user"){
console.log(resquest);
}
else{
setItem("isRegistered", resquest[0].user);
}
}).catch((err: any) => {
console.log(err);
setIngresar(false)
})
GET方法的完整路径是
https://sxxxcex-cxxfc.web.app/xx.x2.xx.74:8000/login/theUSer/ThePassword
但应该是:
https://xx.x2.xx.74:8000/login/theUSer/ThePassword
有人能告诉我如何在没有 sxxxcex-cxxfc.web.app 的情况下发送最后一个网址吗?
【问题讨论】:
-
你试过这样吗? const url = 'https://xx.x2.xx.74: 8000/login';然后是你的代码。
-
是的,我做到了。我试过了
-
那不行吗?
-
https://sxxxcex-cxxfc.web.app/xx.x2.xx.74:8000/login/theUSer/ThePassword是axios想出来的相对路径,因为'xx.x2.xx.74:8000/login/'之前没有https:// -
嗨@codemonkey。我知道。但它会将请求发送到另一个域。
标签: javascript reactjs typescript axios