【问题标题】:Amazon Cognito Error : Unable to resolve host cognito-identity.us-east-1.amazonaws.comAmazon Cognito 错误:无法解析主机 cognito-identity.us-east-1.amazonaws.com
【发布时间】:2015-04-03 04:08:01
【问题描述】:

尝试使用 Cognito(在 Android 应用中)获取托管在 s3 上的文件,如下所示:

....
         AmazonS3 s3 = new AmazonS3Client(getCredentials(MyActivity.this));
         S3Object object = s3.getObject(new GetObjectRequest("mybucket", "myfile"));
....

public static CognitoCachingCredentialsProvider  getCredentials(Context ctx)
    {
        CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider(
                ctx,
                "us-east-1:xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx", /* Identity Pool ID */
                Regions.US_EAST_1 /* Region */
            );
        return cognitoProvider;
    }

显示此错误:

Unable to execute HTTP request: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname
: I/AmazonHttpClient(3427): java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname
: I/AmazonHttpClient(3427):     at java.net.InetAddress.lookupHostByName(InetAddress.java:400)
: I/AmazonHttpClient(3427):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)

可能出了什么问题?

【问题讨论】:

    标签: android amazon-web-services amazon-s3 amazon-cognito


    【解决方案1】:

    您可能忘记包含以下权限:

    <uses-permission android:name="android.permission.INTERNET" />
    

    更多详情请查看Set Up the SDK for Android

    【讨论】:

      【解决方案2】:

      如果手机互联网数据未打开,也会发生此错误。在向云服务发出请求之前,请务必检查设备互联网或数据服务是否已启用/可用。

      【讨论】:

      • 如何防止这种崩溃,比如如果没有互联网至少应该显示消息没有连接或什么?
      猜你喜欢
      • 1970-01-01
      • 2019-01-11
      • 2012-01-25
      • 2019-12-19
      • 2014-11-10
      • 2017-06-07
      • 2019-10-03
      • 1970-01-01
      • 2011-05-20
      相关资源
      最近更新 更多