我正在尝试从SharePoint托管的应用程序调用Exchange Online Server的Exchange Web服务(EWS)。因此,我仅限于使用Javascript。在我的通话过程中,我总是收到拒绝访问错误。
SOAP 请求的主体很好,因为我已经使用客户端应用程序对其进行了测试,但我无法通过 jquery ajax 调用让它工作。我确信这是一个身份验证问题,并且在通话期间发送凭据没有问题。我已经将它们添加到标题中。我最终做了以下事情,但仍然没有运气。
functionGetUnReadEmailCount() {
varsoapPacket = "<?xml version='1.0' encoding='utf-8'?>"+
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'>"+
'<soap:Header>'+
'<wsse:Security>'+
'<wsse:UsernameToken>'+
'<wsse:Username>******</wsse:Username>'+
'<wsse:Password>******</wsse:Password>'+
'</wsse:UsernameToken>'+
'</wsse:Security>'+
'</soap:Header>'+
"<soap:Body>"+
"<FindItem xmlns='http://schemas.microsoft.com/exchange/services/2006/messages' xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'Traversal='Shallow'>"+
"<ItemShape>"+
"<t:BaseShape>IdOnly</t:BaseShape>"+
"</ItemShape>"+
"<IndexedPageItemView MaxEntriesReturned='50' Offset='0' BasePoint='Beginning' />"+
"<Restriction>"+
"<t:IsEqualTo>"+
"<t:FieldURI FieldURI='message:IsRead' />"+
"<t:FieldURIOrConstant>"+
"<t:Constant Value='false' />"+
"</t:FieldURIOrConstant>"+
"</t:IsEqualTo>"+
"</Restriction>"+
"<ParentFolderIds>"+
"<t:DistinguishedFolderId Id='inbox' />"+
"</ParentFolderIds>"+
"</FindItem>"+
"</soap:Body>"+
"</soap:Envelope>";
$.support.cors = true;
$.ajax({
url: "https://outlook.office365.com/EWS/Exchange.asmx",
type: "POST",
dataType: "xml",
data: soapPacket,
complete: processResult,
error: OnError,
contentType: "text/xml; charset="utf-8""
});
}
任何帮助都非常感谢。
谢谢。
埃利
EWS 不支持 CORS。 我猜这就是您的请求不成功的原因。 您能否向我们展示您收到的错误。 我们正在努力为邮件、日历和联系人的 Office 365 REST API 添加 CORS 支持,这应该很快就会推出。 这对你有用吗?