Microsoft Outlook 和其他日历客户端可以订阅“Internet 日历”。
对于 Outlook,它接受 URL(http: 或 webcal:)。正确配置后,Outlook 客户端中显示的“Internet 日历”将保持最新状态。
我想知道如何自己发布“互联网日历”。我正在使用 Java。我已经在使用iCal4j库创建“.ics 文件”事件。我模糊地假设我需要创建一个发送ics事件流的 servlet。
任何让我入门的示例或参考文档将不胜感激。
我不知道您的实现是什么样的,但是当我尝试使用 Spring Boot 进行一些虚拟实现时,我能够完成这项工作。这是我使用的实现:
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
@Slf4j
@Controller
public class CalendarController {
@GetMapping("/calendar.ics")
@ResponseBody
public byte[] getCalendars() throws IOException {
ClassPathResource classPathResource = new ClassPathResource("Test.ics");
InputStream inputStream = classPathResource.getInputStream();
byte[] bytes = inputStream.readAllBytes();
inputStream.close();
return bytes;
}
@GetMapping("/downloadCalendar.ics")
public ResponseEntity<Resource> downloadFile(HttpServletRequest request) {
Resource resource = new ClassPathResource("Test.ics");
String contentType = null;
try {
contentType = request.getServletContext().getMimeType(resource.getFile().getAbsolutePath());
} catch (IOException ex) {
log.info("Could not determine file type.");
}
if(contentType == null) {
contentType = "application/octet-stream";
}
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(contentType))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
.body(resource);
}
}
如果我尝试添加http://localhost:8080/calendar.ics
或. 这两种方法在 Outlook 2016 及更高版本中都可以正常工作http://localhost:8080/downloadCalendar.ics
。Test.ics
我要返回的只是从我的日历中以 ics 格式导出的约会。另外作为旁注,这里是随 Outlook 请求一起发送的标头:
headers = [
accept: "*/*",
user-agent: "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; Microsoft Outlook 16.0.4861; ms-office; MSOffice 16)",
accept-encoding: "gzip, deflate",
host: "localhost:8080",
connection: "Keep-Alive"
]
我还想如果https
使用身份验证可能会出现一些问题,并且在这种情况下 Outlook 可能会发送不同的标头。微软支持中心有一些问题报告:https: //support.microsoft.com/en-us/help/4025591/you-can-t-add-an-internet-calendar-in-outlook,但有到“新现代身份验证”页面的链接断开:)。希望这可以帮助。