以下是我的代码
AmazonS3 s3 = new AmazonS3Client(credentials,config); // assume proper authentication
// generating URL for some bucket(XYZ) and key(test/abc.txt)
java.util.Date expiration = new java.util.Date();
expiration.setTime(6000*10*20);
GeneratePresignedUrlRequest generateUrl = new GeneratePresignedUrlRequest("XYZ", "test/abc.txt");
generateUrl.setMethod(HttpMethod.GET); // Default.
generateUrl.setExpiration(expiration);
URL url = s3.generatePresignedUrl(generateUrl);
使用上面的URL我试图下载abc.txt但是我收到错误403(服务器返回HTTP响应代码:403为URL:)
请告诉我如何使用amazon s3的网址下载文件。
答案 0 :(得分:1)
使用HttpURLConnection
您应该能够从java访问所请求的网页。请尝试以下代码:
HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
httpcon.addRequestProperty("User-Agent", "YOUR_BROWSER_AGENT");