You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为Nativescript移动应用本地开发Golang后端的技术问题咨询

Hey Tony, let's work through the common issues you might run into with your setup and how to fix them:

Troubleshooting Nativescript App Access to Local Golang Backend

First off, using http://localhost:8080/ in your emulator is almost certainly going to fail—here's why, plus step-by-step fixes:

1. Fix the Localhost Mismatch

The emulator's localhost points to its own internal system, not your development machine. You need to use your machine's local network IP address instead:

  • Find your IP: On Windows run ipconfig, on Mac/Linux run ifconfig or ip addr (look for a line like inet 192.168.x.x)
  • Update your request URL to something like: http://192.168.1.105:8080/

2. Make Sure Your Golang Backend is Accessible

If your Go server is only listening on localhost, it won't accept connections from external devices (including emulators). Update your server code to listen on all network interfaces:

// Replace this:
http.ListenAndServe("localhost:8080", nil)
// With this:
http.ListenAndServe(":8080", nil)

3. Actually Trigger the HTTP Request (Angular Fix)

Angular's http.get() returns an observable, which won't execute until you subscribe to it. Your current code doesn't send the request at all—fix it like this:

public get_test(){
  this.http.get("http://YOUR_LOCAL_IP:8080/")
    .subscribe(
      (response) => {
        console.log("Success!", response.text());
        // Handle your response data here
      },
      (error) => {
        console.error("Request failed:", error);
        // Add error handling logic here
      }
    );
}

4. Double-Check Permissions (Android)

Nativescript usually adds internet permissions automatically, but it's worth verifying:

  • Make sure AndroidManifest.xml includes:
    <uses-permission android:name="android.permission.INTERNET"/>
    

For future deployment, if you're new to backend hosting, platforms like Railway or Fly.io are great for beginners—they let you deploy Go apps with just a few commands, no complex server setup needed.

内容的提问来源于stack exchange,提问作者Tony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:39:26