這個賞金已經結束。這個問題的答案有資格獲得 50聲望獎勵。賞金寬限期將在23 小時后結束。 Zak FST希望引起對這個問題的更多關注。
我正在研究電子郵件跟蹤像素專案,我想確保用戶在考慮“閱讀”之前至少花 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回應?
uj5u.com熱心網友回復:
也許 302 重定向會對您有所幫助。定義不是一個,而是兩個入口點就足夠了。
- 第一個點
@GetMapping("/wait30second/{emailID}"),收到請求后,休眠 30 秒,然后向第二個點發送 302 重定向...your-site.../images/{emailID},例如:https : //www.baeldung.com/spring-redirect-and-forward - 第二點
@GetMapping("/images/{emailID}")只是在service.saveTracking(emailID)沒有 30 秒的停頓的情況下修復了對像素的重復訪問 。302重定向由客戶端執行。因此,如果沒有重復上訴,則表示該信件沒有被閱讀。
但是,請記住,隨著此類監控的大量使用,您的電子郵件被標記為垃圾郵件的風險很高。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/321968.html
