AWS API Gateway端点在postman中正常工作,在Android App中返回400 Bad Request

时间:2017-03-22 17:04:07

标签: java android amazon-web-services aws-lambda aws-api-gateway

所以我熟悉AWS Lambda + API网关,并且遇到了一个奇怪的错误。端点在Postman中工作正常,但是当我尝试在我的应用程序中实现它时,我得到400的状态错误。这是我的代码:

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

    final ApiRequest apiRequest = new ApiRequest(client.getClass().getSimpleName())
            .withPath("/path")
            .withHttpMethod(HttpMethodName.valueOf("POST"))
            .addHeader("Content-Type", "application/json")
            .addHeader("Content-Length", String.valueOf(content.length))
            .withBody(content);

    new Thread(new Runnable() {

        @Override
        public void run() {
            try {

                Log.e("TRY", "Thread trying");

                // Invoke the API
                final ApiResponse response = client.execute(apiRequest);

                final int statusCode = response.getStatusCode();
                final String statusText = response.getStatusText();

                Log.e("API_RESPONSE", "Response Status: " + statusCode + " " + statusText);

                // TODO: Add your custom handling for server response status codes (e.g., 403 Forbidden)

            } catch (final AmazonClientException exception) {
             //   Log.e(LOG_TAG, exception.getMessage(), exception);

                // TODO: Put your exception handling code here (e.g., network error)
            }
        }
    }).start();

0 个答案:

没有答案