当前正在使用JAVA EWS-API 2.0版本并获得401未经授权的异常。
我当前正在使用WebCredentials和TokenCredentials,在两种情况下我都遇到以下异常:
"The request failed. The request failed. The remote server returned an error: (401)Unauthorized"
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("XXX@domail.com",password;
service.setUrl(new URI("https://outlook.office365.com/EWS/Exchange.asmx" ));
service.setCredentials(credentials);
EmailMessage msg= new EmailMessage(service);
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
msg.setSubject("Hello world!");
msg.getToRecipients().add( new EmailAddress( "xxx@com" ) );
msg.send();