如何从移动设备访问本地Cloud Endpoints API [英] How to access local Cloud Endpoints API from mobile device

查看:109
本文介绍了如何从移动设备访问本地Cloud Endpoints API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to access my Cloud Endpoints API hosted on my local dev machine from an Android app running on a mobile device I use for testing.

我的设备可以访问我的开发机器通过IP地址。我将--host = 192.1.168.101传递给App Engine启动器,以便我的本地App Engine实例绑定到IP地址。尽管我可以从192.168.1.101访问App Engine实例,但是当我的应用程序进行API调用时,我得到了一个404实例。

My device can access my dev machine by IP address. I passed --host=192.1.168.101 to the App Engine launcher so that my local App Engine instance binds to the IP address. Although I can access the App Engine instance from 192.168.1.101, I get a 404 when my app makes an API call.

我注意到 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地址作为主机不适用于云端点。

I noticed that going to http://192.168.1.101:9080/_ah/api/explorer/ does not show my API; it redirects to https://developers.google.com/apis-explorer/#p/. If I use http://localhost:9080/_ah/api/explorer/ I'm able to see my API as intended. It seems that using an IP address as the host is not working with Cloud Endpoints.

我不想根设备来更改其/ etc / hosts文件。无论如何,改变这可能不是一个解决方案,因为我无法将我的App Engine实例绑定到localhost以外的主机名。

I'd rather not root my device to change its /etc/hosts file. Changing that might not be a solution anyway, since I'm unable to bind my App Engine instance to a hostname other than localhost.

这是我的app.yaml config:

This is my app.yaml config:

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


推荐答案

使用IP地址。我需要在我的API方法装饰器中包含一个路径:

The problem had nothing to do with the IP address. I needed to include a path in my API method decorator:

@endpoints.method(HelloRequest, HelloResponse, name='helloworld', path='test', http_method='GET')
    def helloworld(self, request):

这篇关于如何从移动设备访问本地Cloud Endpoints API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆