AWS IAM创建新的用户返回HTML而不是XML响应的android [英] AWS iam create new user returning html instead of xml response android

查看:285
本文介绍了AWS IAM创建新的用户返回HTML而不是XML响应的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建通过Android应用程序的新用户编程方式使用亚马逊网络服务。 这里是我的code(AsyncTask的):

I am creating a new user through android app programatically using amazon web-service. here is my code(asynctask):

private class S3RegisterNewUser extends AsyncTask<String, Void, String> {

            ProgressDialog dialog;
            String email;
             public S3RegisterNewUser(String email) {
                // TODO Auto-generated constructor stub
                this.email=email;
            }


            protected void onPreExecute() {
                dialog = new ProgressDialog(S3UploaderActivity.this);
                dialog.setMessage(S3UploaderActivity.this
                        .getString(R.string.plswait));
                dialog.setCancelable(false);
                dialog.show();
            }


            protected String doInBackground(String ...strings) {
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost(Constants.REGISTER); //url[0]

                    String result = "";
                    boolean result_recvd = false;
                    boolean ifallset = false;

//                  sparser = new ParsingClass();

                    try {
                      // Add your data
                      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                      nameValuePairs.add(new BasicNameValuePair("UserName",email));
                      nameValuePairs.add(new BasicNameValuePair("Path","/"));
                      nameValuePairs.add(new BasicNameValuePair("Version","2010-05-08"));


                      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));


                   // Execute HTTP Post Request
                      /*HttpResponse response = httpclient.execute(httppost);
                      HttpEntity entity = response.getEntity();
                      is = entity.getContent();
                      bindDataToListing(is);*/

                      HttpResponse resp = httpclient.execute(httppost);
                      HttpEntity ent = resp.getEntity();
                      ist = ent.getContent();
                      result = getStringFromInputStream(ist);



                      if(!result.contains("result")) {
                          Toast.makeText(S3UploaderActivity.this, "No connection or data not received from server", Toast.LENGTH_SHORT).show();

                          //result = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml><result>0</result><message>"+Constants.noConnection+"</message></xml>";
                          result_recvd = false;
                      }else{
                          /** Result has been received from server which contains atleast the 'result' TAG 
                           *  This helps us to know if data is being fetched from server or not.*/
                          result_recvd = true;
                      }

                     // ifallset = bindDataToListing(result, result_recvd);

                      if(!result.contains("result")){
                          Toast.makeText(S3UploaderActivity.this, "No connection or data not received from server", Toast.LENGTH_SHORT).show();
                      }

                      //result = convertStreamtoString(is);

                      Log.e("-- parseResultXML: ", ""+result);

                    } catch (ClientProtocolException e) {
                      e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }



                }  catch (AmazonClientException ace) {
                    System.out.println("Caught an AmazonClientException, " +
                            "which means the client encountered " +
                            "an internal error while trying to communicate" +
                            " with S3, " +
                            "such as not being able to access the network.");
                    System.out.println("Error Message: " + ace.getMessage());
                }
                return null;
            }

            protected void onPostExecute(String file_url) {

                dialog.dismiss();


            }


        }

          /** Convert input stream to a String 
         * @param is -Supply the input stream variable here */
        private String getStringFromInputStream(InputStream is) {
            StringBuilder sb = new StringBuilder();
            String line;
            try {
                br = new BufferedReader(new InputStreamReader(is));
                while ((line = br.readLine()) != null) {
                    sb.append(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (br != null ) {
                    try {
                        br.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return sb.toString();
        }   

Constants.REGISTER =htt​​ps://iam.amazonaws.com/

我下面的荫文档。但代替根据我recieving HTML响应的文档recieving XML结果如下图所示:

I am following the Iam documentation.But instead of recieving xml result according to the documentation I am recieving HTML responses like below:

06-20 15:05:55.856: E/-- parseResultXML:(665): <!DOCTYPE html><!--[if lt IE 7]><html class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7 lang-en lang-en_US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]--><!--[if IE 7]><html class="no-js lt-ie10 lt-ie9 lt-ie8 lang-en lang-en_US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]--><!--[if IE 8]><html class="no-js lt-ie10 lt-ie9 lang-en lang-en_US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]--><!--[if IE 9]><html class="no-js lt-ie10 lang-en lang-en_US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]--><!--[if gt IE 9]><!--><html class="no-js lang-en lang-en_US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml"> <!--<![endif]--> <head>   <meta http-equiv="content-type" content="text/html; charset=UTF-8" />   <link rel="dns-prefetch" href="//a1.awsstatic.com" />   <link rel="dns-prefetch" href="//a0.awsstatic.com" />   <link rel="dns-prefetch" href="//d0.awsstatic.com" />   <meta name="viewport" content="width=device-width, initial-scale=1.0" />   <title>AWS Identity and Access Management (IAM) in the Cloud</title>   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />   <link rel="icon" type="image/ico" href="//a1.awsstatic.com/images/site/favicon.ico" />   <link rel="shortcut icon" type="image/ico" href="//a1.awsstatic.com/images/site/favicon.ico" />   <link rel="apple-touch-icon" sizes="57x57" href="//a1.awsstatic.com/images/site/touch-icon-iphone-114-precomposed.png" />   <link rel="apple-touch-icon" sizes="72x72" href="//a1.awsstatic.com/images/site/touch-icon-ipad-144-precomposed.png" />   <link rel="apple-touch-icon" sizes="114x114" href="//a1.awsstatic.com/images/site/touch-icon-iphone-114-precomposed.png" />   <link rel="apple-touch-icon" sizes="144x144" href="//a1.awsstatic.com/images/site/touch-icon-ipad-144-precomposed.png" />   <meta property="og:title" content="AWS Identity and Access Management (IAM) in the Cloud" />   <meta property="og:type" content="company" />   <meta property="og:url" content="//aws.amazon.com/iam/" />   <meta property="og:image" content="//a1.awsstatic.com/images/open-graph/opengraph.gif" />   <meta property="og:site_name" content="Amazon Web Services, Inc." />   <meta name="google-site-verification" content="XHghG81ulgiW-3EylGcF48sG28tBW5EH0bNUhgo_DrU" />   <meta name="msvalidate.01" content="6F92E52A288E266E30C2797ECB5FCCF3" />   <link rel="canonical" href="http://aws.amazon.com/iam/" />   <link rel="alternate" href="//aws.amazon.com/de/iam/" hreflang="de-de" />   <link rel="alternate" href="//aws.amazon.com/es/iam/" hreflang="es-es" />   <link rel="alternate" href="//aws.amazon.com/fr/iam/" hreflang="fr-fr" />   <link rel="alternate" href="//aws.amazon.com/jp/iam/" hreflang="ja-jp" />   <link rel="alternate" href="//aws.amazon.com/pt/iam/" hreflang="pt-br" />   <link rel="alternate" href="//aws.amazon.com/ko/iam/" hreflang="ko-kr" />   <link rel="alternate" href="//aws.amazon.com/cn/iam/" hreflang="zh-cn" />   <link rel="stylesheet" href="//a1.awsstatic.com/css/35/style.css" />   <!--[if lt IE 9]>    <script src="//a1.awsstatic.com/js/35/jquery.1.9.js"></script>  <![endif]-->   <!--[if (gte IE 9) | (!IE)]><!-->   <script src="//a1.awsstatic.com/js/35/jquery.2.0.js"></script>   <!--<![endif]-->   <script src="//a1.awsstatic.com/js/35/aws-target-mediator.js"></script>   <script>AWS.TargetMediator.init();</script>   <script src="//a1.awsstatic.com/js/35/modernizr.js"></script>   <script>    var require = {      baseUrl: "//a1.awsstatic.com/js/35/",      paths: {        "jquery": "jquery-amd"      },      deps: ["scripts"],      shim: {        "scripts": ["jquery"],        "forms": ["jquery"],        "pricing-table": ["jquery"

如果我做错了什么,或将一些错误的参数,那么code必须抛出一个异常,或者stop.But为什么它返回这个HTML文件?什么错了,我在这里做什么?

If I am doing something wrong or sending some wrong parameters then the code must throw an exception or stop.But why it is returning this HTML file??What wrong I am doing here??

推荐答案

AWS的SDK为Android似乎有点欠缺的入门前确实 - 这似乎是设计相当类似AWS的Java SDK虽然(当然):

Update

The AWS SDK for Android seems to be a bit lacking on the getting started front indeed - it seems to be designed fairly similar to the AWS SDK for Java though (naturally):

在这里,每AWS服务具有其自己的服务特定的客户端,这将是<一href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/identitymanagement/AmazonIdentityManagementClient.html"相对=nofollow> AmazonIdentityManagementClient 为您的使用情况。由于它不存在,它似乎AWS的SDK为Android并不直接支持IAM,所以你需要求助于的 IAM查询API 的确实(如提及页),也就是你会需要实现href="http://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html" rel="nofollow">签名[的]的的自己,很遗憾。

There, every AWS service has its own service specific client, which would be AmazonIdentityManagementClient for your use case. Given it is absent, it seems the AWS SDK for Android doesn't support IAM directly, so you'd need to resort to the IAM Query API indeed (as mentioned on that page), i.e. you'll need to implement the Signing [of] AWS API Requests yourself, unfortunately.

AWS服务和一般亚马逊IAM 特别需要的登录[中] AWS API请求的,即你不能简单地调用API的端点,而你需要你 AWS安全凭据,以产生的数字签名它提交给API之前,每个请求。

AWS services in general and Amazon IAM in particular require the Signing [of] AWS API Requests, i.e. you cannot simply call an API endpoint, rather you need your AWS Security Credentials to generate a Digital Signature for each request before submitting it to the API.

请求签名过程是一个有点复杂,虽然也AWS服务之间变化,所以我会强烈建议简单地使用的 AWS SDK为Android 来代替,该做的所有繁重的你 - 这也适用于处理AWS顺便说一句其他的复杂性,所以即使你在概念上,其实我从来没有使用AWS没有,如果没有任何具体的理由这样做(例如:正在上不支持许多的官方AWS的SDK 还)。

The request signing process is a bit complex though and also varies between AWS services, so I'd highly recommend to simply use the AWS SDK for Android instead, which does all the heavy lifting for you - this also applies for any other complexities in dealing with AWS btw., so even if you can conceptually, I'd actually never use AWS without a SDK if there isn't any specific reason to do so (e.g. being on a platform not supported by one of the many offical AWS SDKs yet).

这篇关于AWS IAM创建新的用户返回HTML而不是XML响应的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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