0
我正在使用AmazonHttpClient & AmazonWebServiceRequest從android應用程序向API網關發出http請求。 requestBody
是一個JSON字符串,DefaultRequest似乎只接受InputStream
作爲內容。如何在AmazoneWebServiceRequest上設置JSON負載
final AmazonWebServiceRequest awsRequest = new AmazonWebServiceRequest() {};
final Request request = new DefaultRequest(awsRequest, UtilConstants.API_GATEWAY_SERVICE_NAME);
request.setEndpoint(uri);
request.setHttpMethod(requestType);
request.addHeader(HttpHeader.CONTENT_TYPE, "application/json");
final InputStream stream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8));
request.setContent(stream);
當我做我得到以下異常請求
Caused by: com.amazonaws.AmazonClientException: Unable to execute HTTP request: expected 0 bytes but received 38