gpt4 book ai didi

google-app-engine - 如何从移动设备访问本地 Cloud Endpoints API

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:34 25 4
gpt4 key购买 nike

我想从我用于测试的移动设备上运行的 Android 应用程序访问我在本地开发机器上托管的 Cloud Endpoints API。

我的设备可以通过 IP 地址访问我的开发机器。我将 --host=192.1.168.101 传递给 App Engine 启动器,以便我的本地 App Engine 实例绑定(bind)到 IP 地址。虽然我可以从 192.168.1.101 访问 App Engine 实例,但当我的应用程序调用 API 时,我会收到 404。

我注意到访问 http://192.168.1.101:9080/_ah/api/explorer/ 没有显示我的 API;它重定向到 https://developers.google.com/apis-explorer/#p/。如果我使用 http://localhost:9080/_ah/api/explorer/ 我就能按预期查看我的 API。使用 IP 地址作为主机似乎不适用于 Cloud Endpoints。

我宁愿不root我的设备来更改它的/etc/hosts文件。改变它可能不是解决方案,因为我无法将我的 App Engine 实例绑定(bind)到本地主机以外的主机名。

这是我的 app.yaml 配置:

application: my-server
version: 1
runtime: python27
threadsafe: true
api_version: 1

handlers:
# Endpoints handler
- url: /_ah/spi/.*
script: services.application

- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico

- url: .*
script: main.app

最佳答案

您绑定(bind)到您的特定 IP,但作为提醒,您也可以绑定(bind)到 0.0.0.0(所有可用 IP)。如果您正在使用 maven appengine 插件并且不想在您的 IP 更改时更新 pom.xml 文件,这将很方便。

接下来,确保您在同一个网络上并且可以在机器之间进行连接。我通常使用 ConnectBot 进行测试,方法是打开一个到您为本地运行定义的 IP 地址和端口的 telnet session 。这将确保您的防火墙不会导致问题。

最后,通过调整 API 的根 URL 来更新您的代码。如果您的 IP 地址是 192.168.1.100 并且端口是 8080,那看起来像这样:

Helloworld.Builder helloWorld = new Helloworld.Builder(AppConstants.HTTP_TRANSPORT,
AppConstants.JSON_FACTORY, credential);
helloWorld.setRootUrl("http://192.168.1.100:8080/_ah/api/");

关于google-app-engine - 如何从移动设备访问本地 Cloud Endpoints API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18651192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com