为了账号安全,请及时绑定邮箱和手机立即绑定

移动设备上的对象 XMLHttpRequestProgressEvent 错误

移动设备上的对象 XMLHttpRequestProgressEvent 错误

暮色呼如 2022-01-13 20:01:53
我有一个 node.js 和 Ionic (angular) 应用程序,当我尝试从我的手机进行 API 调用时,我收到了这个错误 -> object XMLHttpRequestProgressEvent我正在像这样服务我的 Ionic 应用程序ionic serve --address=10.0.0.107。它不适用于来自客户端的每个电话仅在电话上,当我从桌面拨打电话时,一切都很好。这是来自 auth.service.ts 的登录部分  loginUser(u: User): Observable<any> {    const url = `${this.baseUrl}/auth`;    const body = { username: u.username, password: u.password };    // When you want to send a cookies with requests,    // you have to put "withCredentials: true" into request option    return this.http.post(url, body, this.noAuthOptions);  }这是我的选择: private readonly baseUrl = "http://localhost:3000"; private readonly contentType = { "Content-Type": "application/json" }; private readonly noAuth = { "No-Auth": "True" }; private readonly header = new HttpHeaders(this.contentType); private readonly noAuthHeader = new HttpHeaders({    ...this.contentType,    ...this.noAuth  }); private readonly options = { headers: this.header, withCredentials: true }; private readonly noAuthOptions = {    headers: this.noAuthHeader,    withCredentials: true  };这是我在 github 上的代码(前端)https://github.com/TenPetr/dashboard 和后端部分:https ://github.com/TenPetr/dashboard_backend你有什么想法,为什么会这样?
查看完整描述

1 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

问题是这一行:

private readonly baseUrl = "http://localhost:3000";

它可以在 PC 上运行,因为它通过 hosts 文件(位于 C:\Windows\System32\drivers\etc\hosts 中)知道此地址

但是,移动设备在本地没有此文件,因此无法解析 url。

您需要运行服务器并将 localhost 替换为您的 IP 地址。 https://ngrok.com/docs#getting-started


查看完整回答
反对 回复 2022-01-13
  • 1 回答
  • 0 关注
  • 784 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号