首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android认证HttpURLConnection

Android认证HttpURLConnection
EN

Stack Overflow用户
提问于 2016-06-02 16:39:45
回答 1查看 824关注 0票数 1

使用认知和API网关访问REST的问题

在我的一生中,我找不到一个简单的例子,说明如何在AWS服务器上调用安全的REST。

我打电话

代码语言:javascript
复制
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                    ProfileViewActivity.this, // get the context for the current activity
                    AMAZON_COGNITO_IDENTITY_POOL_ID, // your identity pool id
                    Regions.US_EAST_1  //Region
            );

然后尝试调用我们的服务器,这是该池的一部分。我不停地收回“禁止”。

我应该如何处理credentialsProvider在HttpURLConnection头中的操作?

更新:

好的,在AWS生成的SDK中正确地使用APIGateWay,但是不确定如何更改生成的文件:

代码语言:javascript
复制
    private class MyAsyncTask extends AsyncTask<String, Void, String> {
    private TextView textView;

    public MyAsyncTask() {
    }

    @Override
    protected String doInBackground(String... strings) {
        AWSCredentialsProvider credenetialsProvider = new CognitoCachingCredentialsProvider(
                ProfileViewActivity.this,          // activity context
                AMAZON_COGNITO_IDENTITY_POOL_ID, // Cognito identity pool id
                Regions.US_EAST_1 // region of Cognito identity pool
        );

        ApiClientFactory factory = new ApiClientFactory()
                .credentialsProvider(credenetialsProvider)
                .region("us-east-1")
                .endpoint("https://myendpoint")
                .apiKey("xxxxxxxxxxxxxxxxxxxxxxx");


        // MyClient is the AWS Android SDK Generated class

            final MyClient client = factory.build(MyClient.class);

         client.feedGet();

        String str  = client.testGet().toString();


        Log.d("###", "here after test" +client.testGet().toString());


        return "DONE";
    }

    @Override
    protected void onPostExecute(String temp) {
        Log.d("####", "onPostExecute");
    }
}

然后

代码语言:javascript
复制
    private class MyAsyncTask extends AsyncTask<String, Void, String> {
    private TextView textView;

    public MyAsyncTask() {
    }

    @Override
    protected String doInBackground(String... strings) {
        AWSCredentialsProvider credenetialsProvider = new CognitoCachingCredentialsProvider(
                ProfileViewActivity.this,          // activity context
                AMAZON_COGNITO_IDENTITY_POOL_ID, // Cognito identity pool id
                Regions.US_EAST_1 // region of Cognito identity pool
        );

        ApiClientFactory factory = new ApiClientFactory()
                .credentialsProvider(credenetialsProvider)
                .region("us-east-1")
                .endpoint("https://myendpoint")
                .apiKey("xxxxxxxxxxxxxxxxxxxxxxx");


        // MyClient is the AWS Android SDK Generated class

            final MyClient client = factory.build(MyClient.class);

         client.feedGet();

        String str  = client.testGet().toString();


        Log.d("###", "here after test" +client.testGet().toString());


        return "DONE";
    }

    @Override
    protected void onPostExecute(String temp) {
        Log.d("####", "onPostExecute");
    }
}

========= MyClient.java - Android生成的文件

代码语言:javascript
复制
    @com.amazonaws.mobileconnectors.apigateway.annotation.Service(endpoint = https:myaws_server)
public interface MyClient {
    @com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = \"/test\", method = "GET")
    Empty testGet();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-03 03:10:37

如果您使用的是AWS网关,您可以独立使用它,而无需使用AWS认知。是一个http服务,就像您服务器的代理或AWS函数的网关一样。

aws api网关

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37597549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档