简体   繁体   English

如何在物理设备而非AVD上测试Google Cloud端点?

[英]How to test google cloud endpoints on physical device instead of AVD?

I am currently testing my google cloud endpoint via the AVD and calling the endpoint api methods like so: 我目前正在通过AVD测试我的Google Cloud端点,并调用端点api方法,如下所示:

if (myApiService == null) {  // Only do this once
                MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                        new AndroidJsonFactory(), null)
                        // options for running against local devappserver
                        // - 10.0.2.2 is localhost's IP address in Android emulator
                        // - turn off compression when running against local devappserver
                        .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                        .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                            @Override
                            public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                                abstractGoogleClientRequest.setDisableGZipContent(true);
                            }
                        });
                myApiService = builder.build();
            }

            try {
                return myApiService.publishReview(mUserId, mReview).execute().getTitle();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }

I use http://10.0.2.2:8080/_ah/api/ as the root url as it is the AVDs IP. 我将http://10.0.2.2:8080/_ah/api/用作根URL,因为它是AVD的IP。 What modifications would need to be made in order to get this call to the endpoint method working on any physical device around the world? 为了使此调用可以在世界各地的任何物理设备上运行的终结点方法,需要进行哪些修改?

As @Selvin said, deploy your project to Google Cloud. 正如@Selvin所说,将您的项目部署到Google Cloud。

You will want to use https://YOUR_PROJECT_ID.appspot.com/_ah/api/ as the root url. 您将要使用https://YOUR_PROJECT_ID.appspot.com/_ah/api/作为根URL。

See this for reference: https://cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java#sending_a_request_to_the_sample_api 参见以下内容以供参考: https : //cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java#sending_a_request_to_the_sample_api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM