【问题标题】:How to POST in AWS cloud logic for Android如何在适用于 Android 的 AWS 云逻辑中发布
【发布时间】:2018-06-13 19:51:02
【问题描述】:

当我使用 AWS Mobile hub 进行云逻辑集成时。

如何将数据发送到 lambda 函数?

代码:

public void postCloudLogic(String mName,String mClass) {
    // Create components of api request
    final String method = "POST";

    final String path = "/test_rds_lambda/?name="+mName+"&class="+mClass;

    final String body = "";
    final byte[] content = body.getBytes(StringUtils.UTF8);

    final Map parameters = new HashMap<>();
    parameters.put("lang", "en_US");

    final Map headers = new HashMap<>();

    // Use components to create the api request
    ApiRequest localRequest =
            new ApiRequest(apiClient.getClass().getSimpleName())
                    .withPath(path)
                    .withHttpMethod(HttpMethodName.valueOf(method))
                    .withHeaders(headers)
                    .addHeader("Content-Type", "application/json")
                    .withParameters(parameters);
    ...

如你所见,我使用过:

final String path = "/test_rds_lambda/?name="+mName+"&class="+mClass;

这是我从中得到的错误:

{message=No method found matching route test_rds_lambda/%3Fname%3DYoME%26class%3DYoClass for http method POST.}

我的请求 URL 路径有

?,=

等,但它们已更改为 HEX。即

%3Fname%3D

当它在 aws 控制台的“test api”中工作时,如何防止这种情况发生。

【问题讨论】:

    标签: amazon-web-services aws-lambda aws-sdk aws-mobilehub


    【解决方案1】:
    【解决方案2】:

    所以,我通过将数据放入 JSONObject 然后将其传递到云逻辑的主体参数来解决了这个问题。

    public void callCloudLogic() throws JSONException {
        // Create components of api request
        final String method = "POST";
    
        final String path = "/lambda_func";
    
        *--> JSONObject data =new JSONObject();
        *--> data.put("mCase","1");
        *--> final String body = data.toString();
        *--> final byte[] content = body.getBytes(StringUtils.UTF8);
    
        final Map parameters = new HashMap<>();
        parameters.put("lang", "en_US");
    
        final Map headers = new HashMap<>();
    
        // Use components to create the api request
        ApiRequest localRequest =
                new ApiRequest(apiClient.getClass().getSimpleName())
                        .withPath(path)
                        .withHttpMethod(HttpMethodName.valueOf(method))
                        .withHeaders(headers)
                        .addHeader("Content-Type", "application/json")
                        ;
    

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 2019-06-08
      • 2012-10-01
      • 2019-04-03
      • 2012-09-09
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多