我有curl命令:捲曲到Java的HttpClient
curl -s -T '/orig.jpg' -H 'content-type:image/jpeg' 'https://amazonaws.com/d5OCmmq-MgbIPk6ZRqql4bZX3gZ2QhG8uum6YDdcZYcRtohs3ZIMxF1gR3rFcPEg1-Vz-v8hUuKATM6D_-FrtQ%3D%3D/orig.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJGCZOCB2ULPVHGAA%2F20160416%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20160416T202457Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Signature=2dcfb2b843d484e50557d2da430e60512a49070bed219ae98970284ef735e02e'
這是正常工作。 後來我想這樣做,但用的HttpClient:
File file = new File(imagePath);
HttpPost post = new HttpPost(url);
post.setHeader(HTTP.CONTENT_TYPE, "image/jpeg");
ContentBody fileBody = new FileBody(file, ContentType.create("image/jpeg"));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addPart("orig.jpg", fileBody);
HttpEntity entity = builder.build();
post.setEntity(entity);
HttpResponse response = periscope.getClient().execute(post);
響應:
SignatureDoesNotMatch。我們計算的請求籤名與您提供的簽名不匹配。檢查你的密鑰和簽名方法。
謝謝,我使用HttpPut和setEntity()方法,它現在工作 –