Axis2 和 Apache Commons Email 之间的编码
我有以下 Webservice 方法,由 REST 调用:
public boolean sendMail(String text) {
Email email = new SimpleEmail();
email.setHostName(MAIL_SERVER);
email.setSmtpPort(25);
email.setAuthenticator(new DefaultAuthenticator(MAIL_USER, MAIL_PASSWORD));
try {
email.setFrom(MAIL_SENDER);
email.setSubject(text);
email.setMsg(text);
email.addTo(MAIL_RECEIVER);
email.send();
return true;
} catch (EmailException e) {
return false;
}
}
请求类似于 sendMail?text=aäoöuü
,它使用 x-www-form-urlencoded
进行编码 sendMail?text=a%E4o%F6u%FC
邮件内容为a?o?u?
。
邮件 API 是 Apache Commons 电子邮件。
如何获得邮件的正确字符编码?
I've got the following webservice method, which is called by REST:
public boolean sendMail(String text) {
Email email = new SimpleEmail();
email.setHostName(MAIL_SERVER);
email.setSmtpPort(25);
email.setAuthenticator(new DefaultAuthenticator(MAIL_USER, MAIL_PASSWORD));
try {
email.setFrom(MAIL_SENDER);
email.setSubject(text);
email.setMsg(text);
email.addTo(MAIL_RECEIVER);
email.send();
return true;
} catch (EmailException e) {
return false;
}
}
The request is like sendMail?text=aäoöuü
which is encode with x-www-form-urlencoded
tosendMail?text=a%E4o%F6u%FC
The content of the mail is a?o?u?
.
Mail API is Apache Commons Email.
How can I get the right character encoding to the mail?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在应用 URL 编码之前,您应该使用 UTF-8 对参数进行编码。
You should encode the parameter using UTF-8 before applying the URL encoding.