向HTTPS查询API发送GET请求的HTTP响应代码400



我正在尝试使用SES HTTPS查询API发送电子邮件。我有一个java方法,可以向Amazon SES端点发送GET请求,我正试图用SES发送一封电子邮件并获取结果。

代码:

public static String SendElasticEmail(String timeConv,String action,String source, String destinationAddr, String subject, String body) {
    try {
        System.out.println("date :    "+timeConv);
        System.out.println("In Sending Mail Method......!!!!!");
        //Construct the data
        String data = "Action=" + URLEncoder.encode(action, "UTF-8");
        data += "&Source=" + URLEncoder.encode(source, "UTF-8");
        data += "&Destination.ToAddresses.member.1=" + URLEncoder.encode(destinationAddr, "UTF-8");
        data += "&Message.Subject.Data=" + URLEncoder.encode(subject, "UTF-8");
        data += "&Message.Body.Text.Data=" + URLEncoder.encode(body, "UTF-8");
        //Send data
        System.out.println("https://email.us-east-1.amazonaws.com?"+data);
        URL url = new URL("https://email.us-east-1.amazonaws.com?"+data);
        //URLConnection conn = url.openConnection();
        HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
        con.setRequestMethod("GET");
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        con.setRequestProperty("x-amz-date" , timeConv);
        con.setRequestProperty("Content-Length", ""+data.toString().length());
        con.setRequestProperty("X-Amzn-Authorization" , authHeader);
        int responseCode = ((HttpsURLConnection) con).getResponseCode();
        String responseMessage = ((HttpsURLConnection) con).getResponseMessage();
        System.out.println("nSending 'GET' request to URL : " + url);
        System.out.println("Response Code : " + responseCode);
        //System.out.println("Response Message : " + responseMessage);
        InputStream stream = con.getInputStream();
        InputStreamReader isReader = new InputStreamReader(stream ); 
        System.out.println("hgfhfhfhgfgfghfgh");
        BufferedReader br = new BufferedReader(isReader);
        String result = "";
        String line;
        while ((line = br.readLine()) != null) {
            result+= line;
        }
        System.out.println(result);
        br.close();
        con.disconnect();
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    return subject;
}

我已经正确地计算了签名,因为从邮递员客户那里点击后得到了200的回复。

URL url = new URL("https://email.us-east-1.amazonaws.com?"+data);

您在问号前遗漏了一个'/'。应该是

URL url = new URL("https://email.us-east-1.amazonaws.com/?"+data);

相关内容

  • 没有找到相关文章

最新更新