节点api在localhost:3000或ip_address:3000上提供,无法从设备(不是模拟器)通过android应用访问

时间:2018-09-27 19:19:38

标签: android ios node.js angular nativescript

构建一个Android应用程序(使用nativescript-angular),并在连接到同一wifi的设备上运行(也通过具有调试器的usb连接到开发机)。

最初,我尝试使用chrome端口转发(设备通过USB连接到开发机时),并尝试了localhost:3000 / api / test。

  
      
  1. 它适用于android的chrome浏览器
  2.   
  3. 在调用该路由的android应用中无法正常运行。
  4.   

我尝试将笔记本电脑和设备连接到同一wifi,并找到了笔记本电脑的ip。然后尝试192.168.0.103:3000/api/test。

  
      
  1. 它适用于chrome浏览器
  2.   
  3. 在调用该路由的android应用中无法正常运行。
  4.   

在ios模拟器上进行了相同的尝试。使用的路径http://localhost:3000/api/test 仍然出现相同的错误。

  

错误:控制台日志文件:///app/shared/user/user.service.js:37:20:   尝试:http://localhost:3000/api/users/test控制台日志   file:///app/shared/user/user.service.js:63:20:错误:响应为   状态:URL的200:空

我使用代码:

return this.http.post(
  Config.apiUrl + "api/users/register",
  {
    email: user.email,
    password: user.password
  },
  { headers: this.getCommonHeaders() }
).pipe(
  map(response => {
    this.setToken(response.headers.toJSON()['x-auth'][0])
    return response.json()
  }),
  catchError(this.handleErrors)
);

移动应用程序中发生了什么?它没有达到服务器端点。

0 个答案:

没有答案