因此,我有一个用于我的Key服务的API密钥。每次用户注册时,我都会给他发送一封电子邮件,让他验证自己的帐户。这看起来像这样:
public class EmailSender {
private static final String username = "somesecretemail@gmail.com";
private static final String password = "uthoughiwillshowyoumypassword?";
public static void sendVerificationCode(String receiverusername, String receiveremail, String code) throws Exception {
Properties prop = new Properties();
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put("mail.smtp.port", "587");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.starttls.enable", "true"); //TLS
Session session = Session.getInstance(prop,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
MimeMessage message = new MimeMessage(session);
message.addRecipient(Message.RecipientType.TO, new InternetAddress(receiveremail));
message.setSubject("Verification Code");
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("<form action=\"https://pathtomywebserviceurl.com/verify/"+code+"\">\n" +
"<input type=\"submit\" value=\"Verify\" />\n" +
"</form>", "UTF-8", "html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
}当他点击按钮时,用户实际上向我的webservice发出了一个请求,并将他的令牌作为参数。但现在我也希望我的API-Key被发送为eg。一个http头,这样我就可以从用户验证请求中提取API-Key,并检查API-Key是否等于实际的API-Key。现在我只发送代码,而不发送API-Key。
发布于 2019-06-13 23:35:11
使用隐藏的表单元素:
<input type="hidden" id="myApiKey" name="myApiKey" value="myApiKeyValue">https://stackoverflow.com/questions/56582965
复制相似问题