【发布时间】:2021-11-27 17:21:35
【问题描述】:
我正在从事电子邮件跟踪像素项目,我想确保用户在考虑“阅读”之前至少花费 30 秒阅读电子邮件
我正在使用 Java Springboot 作为后端服务器和 HTML 来创建电子邮件模板
在我的模板中,我将此像素用于跟踪:
<img id="tr_pixel" src="https://localhost:8080/api/v1/images/1"/>
一旦图像被加载,它将请求我的服务器:
@GetMapping("/images/{emailID}")
public ResponseEntity<byte[]> getImagePixel (@Pathvariable String emailID) {
try{
// wait 30seconds before saving the event
Thread.sleep(30000);
// If the connection with the client is lost, throw an exception and ignore the next line
//save tracking only if user spend > 30s
service.saveTracking(emailID);
return ok().contentType(IMAGE_PNG).body(pixel);
} catch (ConnectionLostException){
// catch connection lost error if the client close the email before 30s or if did not receive the response
}
}
有没有办法检查与客户端的连接是否丢失,或者客户端是否收到http响应?
【问题讨论】:
标签: java html http spring-mvc outlook