1
當我嘗試連接到Exchange服務器,我有一個401錯誤:交換網絡服務(EWS)的Java API:401未經授權
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. The remote server returned an error: (401)Unauthorized
我https://ewseditor.codeplex.com/測試(有相同的用戶id,userPw,域和網址),它完美的作品。
這是我的實際代碼:
public static void main(String[] args)
{
try {
CustomExchangeService service = new CustomExchangeService(version);
ExchangeCredentials credentials = new WebCredentials(userId, userPw,domain);
service.setUrl(new URI(url));
service.setCredentials(credentials);
service.setTraceEnabled(true);
Folder.bind(getInstance().service, WellKnownFolderName.Inbox, PropertySet.IdOnly);
} catch (Exception e) {
e.printStackTrace();
}
}
和類CustomExchangeService此方法:
protected Registry<ConnectionSocketFactory> createConnectionSocketFactoryRegistry() {
try {
return RegistryBuilder.<ConnectionSocketFactory>create()
.register(EWSConstants.HTTP_SCHEME, new PlainConnectionSocketFactory())
.register(EWSConstants.HTTPS_SCHEME, EwsSSLProtocolSocketFactory.build(
null, NoopHostnameVerifier.INSTANCE
))
.build();
} catch (GeneralSecurityException e) {
throw new RuntimeException(
"Could not initialize ConnectionSocketFactory instances for HttpClientConnectionManager", e
);
}
}
爲什麼我有這樣的錯誤?也許是因爲SSL的事情?
感謝您的幫助
錯誤與憑據,如果它是SSL,你會得到一個不同的錯誤返回。檢查您可能想要嘗試使用UPN作爲用戶名的憑證格式,然後您只需要用戶名,密碼作爲憑證 –
已解決:在服務器上,打開Internet信息服務(IIS)管理器。在左側部署以查找EWS。點擊身份驗證並使用401來激活所有的ligne。 – Gabriel