You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用EWS Java API查询其他用户忙闲状态时持续报404错误

问题描述

使用官方EWS Java API及示例代码调用接口查询其他用户的忙闲状态时,始终返回404错误。

示例代码

// Create a list of attendees for which to request availability
// information and meeting time suggestions.

List<AttendeeInfo> attendees = new ArrayList<AttendeeInfo>();
attendees.add(new AttendeeInfo("test@contoso.com"));
attendees.add(new AttendeeInfo("temp@contoso.com"));

SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");

//minimum time frame allowed by API is 24 hours
Date start = formatter.parse("2010/05/18"); 
Date end = formatter.parse("2010/05/19");

// Call the availability service.
GetUserAvailabilityResults results = service.getUserAvailability(
    attendees,
    new TimeWindow(start, end),
    AvailabilityData.FreeBusyAndSuggestions);

// Output attendee availability information.
int attendeeIndex = 0;

for (AttendeeAvailability attendeeAvailability : results.getAttendeesAvailability()) {
    System.out.println("Availability for " + attendees.get(attendeeIndex));
    if (attendeeAvailability.getErrorCode() == ServiceError.NoError) {
        for (CalendarEvent calendarEvent : attendeeAvailability.getCalendarEvents()) {
            System.out.println("Calendar event");
            System.out.println("  Start time: " + calendarEvent.getStartTime().toString());
            System.out.println("  End time: " + calendarEvent.getEndTime().toString());

            if (calendarEvent.getDetails() != null)
            {
                System.out.println("  Subject: " + calendarEvent.getDetails().getSubject());
                // Output additional properties.
            }
        }
    }

    attendeeIndex++;
}


// Output suggested meeting times.
for (Suggestion suggestion : results.getSuggestions()) {
    System.out.println("Suggested day: " + suggestion.getDate().toString());
    System.out.println("Overall quality of the suggested day: " + suggestion.getQuality().toString());

    for (TimeSuggestion timeSuggestion : suggestion.getTimeSuggestions()) {
        System.out.println("  Suggested time: " + timeSuggestion.getMeetingTime().toString());
        System.out.println("  Suggested time quality: " + timeSuggestion.getQuality().toString());
        // Output additonal properties.
    }
}

错误信息

Proxy web request failed. , inner exception: System.Net.WebException: The remote server returned an error: (404) Not Found.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at Microsoft.Exchange.InfoWorker.Common.Availability.Proxy.RestService.EndGetSchedule(IAsyncResult asyncResult)
   at Microsoft.Exchange.InfoWorker.Common.Availability.FreeBusyApplication.EndRestProxyWebRequest(RestProxyWebRequest proxyWebRequest, QueryList queryList, RestService service, IAsyncResult asyncResult)
   at Microsoft.Exchange.InfoWorker.Common.Availability.RestProxyWebRequest.EndInvoke(IAsyncResult asyncResult)
   at Microsoft.Exchange.InfoWorker.Common.Availability.AsyncWebRequest.EndInvokeWithErrorHandling()

解决方案
  • 确认EWS端点正确性
    404错误最常见原因是EWS URL配置错误,不同Exchange环境的标准端点:

    • Office 365/Exchange Online: https://outlook.office365.com/EWS/Exchange.asmx
    • 本地Exchange服务器: https://<你的Exchange服务器域名>/EWS/Exchange.asmx
      建议开启自动发现功能自动获取正确端点,避免手动配置错误:
    service.autodiscoverUrl("your-account@contoso.com", redirectionUrl -> {
        // 仅信任HTTPS重定向
        return redirectionUrl.toLowerCase().startsWith("https://");
    });
    
  • 检查权限配置

    • 本地Exchange:需在Exchange管理中心配置可用性地址空间,授予调用者读取目标用户忙闲的权限。
    • Exchange Online:默认允许组织内用户查看其他用户的忙闲信息,若目标用户手动限制了权限,需调整其日历共享设置。
  • 排查代理与网络问题
    错误提示Proxy web request failed,需确认:

    • 代理配置是否正确,若无需代理可禁用:service.getHttpHeaders().remove("Proxy-Authorization");
    • 直接通过浏览器或curl测试EWS端点是否可达,排除网络防火墙拦截:
      curl -i https://outlook.office365.com/EWS/Exchange.asmx
      
  • 验证目标邮箱有效性
    示例代码中的测试邮箱需替换为实际存在的、同组织内的有效邮箱地址,无效邮箱可能触发间接404错误。

  • 规范时间范围处理
    API要求时间范围至少覆盖24小时,建议使用DateTime类处理时间(避免时区问题):

    DateTime start = new DateTime(2024, 5, 18, TimeZone.getTimeZone("UTC"));
    DateTime end = start.plusDays(1);
    TimeWindow timeWindow = new TimeWindow(start, end);
    

内容的提问来源于stack exchange,提问作者elvaone

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 09:53:20