1

我正在使用 gwt 2.5,GAE 1.7.4。我正在尝试连接 Amazon S3 并上传文件,但出现连接拒绝错误。而且我没有从亚马逊教程中找到任何解决方案。我的代码如下:

try{

        URL url = new URL("https://temptxt.s3-website-us-east-1.amazonaws.com");

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);

        String userName = "MyAccessKey".trim();
        String password = "MySecretKey".trim();

        String authString = userName + ":" + password;
        String authStringBase64 = Base64.encodeBase64String(authString.getBytes());
        authStringBase64 = authStringBase64.trim();

        connection.setRequestProperty("Content-type", "text/plain");
        connection.setRequestProperty("Authorization", "AWS" + authStringBase64);

        int responseCode = connection.getResponseCode();
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        String decodedString;
        while ((decodedString = in.readLine()) != null) {
            System.out.println("Read Data From Response : " + decodedString);
        }
        in.close();

        if (responseCode == 401) {
            throw new IllegalStateException("Error 401");
        }
    }catch (Exception e) {
        System.out.println("Error : "+e);
    }
4

0 回答 0