首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在HTML表单中发送API-key

在HTML表单中发送API-key
EN

Stack Overflow用户
提问于 2019-06-13 22:39:04
回答 1查看 692关注 0票数 1

因此,我有一个用于我的Key服务的API密钥。每次用户注册时,我都会给他发送一封电子邮件,让他验证自己的帐户。这看起来像这样:

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 23:35:11

使用隐藏的表单元素:

代码语言:javascript
复制
<input type="hidden" id="myApiKey" name="myApiKey" value="myApiKeyValue">
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56582965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档