发送GetItem请求时出现HTTP 401未经授权的错误

发送GetItem请求时出现HTTP 401未经授权的错误

问题描述:

我正在使用EWS GetItem操作从交换服务器获取数据,但是出现以下错误

I'm using EWS GetItem operation to fetch data from exchange server, but i've got following error

Error 401 fault: SOAP-ENV:Server[no subcode] "HTTP Error" Detail: HTTP/1.1 401 Unauthorized

Error 401 fault: SOAP-ENV:Server[no subcode] "HTTP Error" Detail: HTTP/1.1 401 Unauthorized

但是我的登录凭据是正确的,因为它们与findItem请求和响应都可以很好地工作,但是当GetItem请求进入服务器时,它会给出上述错误.我的凭据如下:

However my login credential are correct, since those are works well with findItem request and response, but when GetItem request goes to server it give above error. My credentials are like:

soap *pSoap = proxy->soap;
proxy->soap_endpoint = "https://outlook.office365.com/ews/exchange.asmx";
pSoap->userid = "abcd@abcd.onmicrosoft.com";
pSoap->passwd = "abcd1234";

接收到的日志就像

HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.0
request-id: b66330dd-37a5-40c0-946f-12a204b2eacb
Set-Cookie: ClientId=OVJLSVEMECIIUMMAXM9JA; expires=Thu, 22-Sep-2016 18:00:57 GMT; path=/; secure; HttpOnly
X-CalculatedBETarget: SG2PR06MB1165.apcprd06.prod.outlook.com
X-BackEndHttpStatus: 200
Set-Cookie: exchangecookie=fa26578c8e659cf1ccc3f50b3a83; expires=Fri, 23-Sep-2016 18:00:58 GMT; path=/; HttpOnly
x-EwsHandler: FindItem
X-AspNet-Version: 4.0.30319
X-DiagInfo: SG2PR06MB1165
X-BEServer: SG2PR06MB1165
Set-Cookie: ClientId=OVJLSVEIIUMMAXM9JA; expires=Thu, 22-Sep-2016 18:00:57 GMT; path=/; secure; HttpOnly
X-Powered-By: ASP.NET
X-FEServer: SG2PR03CA0031
Date: Wed, 23 Sep 2015 18:00:58 GMT
Connection: close

17d
<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="268" MinorBuildNumber="21" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
1e8
</s:Header><s:Body><m:FindItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><m:ResponseMessages><m:FindItemResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:RootFolder TotalItemsInView="2" IncludesLastItemInRange="true"><t:Items><t:Message><t:ItemId Id="
edAQAfAGNvObtNFsAAAA==" ChangeKey="CQfwjm7TRbAAAAAAWl"/></t:Message><t:Message><t:ItemId Id="
133AQAfAGCObtNFsAAAIFUAAAAA==" ChangeKey="CQAAABYAAACZNImAAAAAWT"/></t:Message></t:Items></m:RootFolder></m:FindItemResponseMessage></m:ResponseMessages></m:FindItemResponse>
</s:Body></s:Envelope>


/*  This below log for getItem Request*/

HTTP/1.1 401 Unauthorized
Server: Microsoft-IIS/8.0
request-id: 7a1a654c-fa72-46b0-ab76-a6045c576d9f
Set-Cookie: ClientId=H8THXUH0BECF9HJMTXHEW; expires=Thu, 22-Sep-2016 18:01:01 GMT; path=/; secure; HttpOnly
X-Powered-By: ASP.NET
X-FEServer: SG2PR03CA0003
WWW-Authenticate: Basic Realm=""
Date: Wed, 23 Sep 2015 18:01:00 GMT
Connection: close
Content-Length: 0

这里可能有什么问题,为什么一个请求通过而另一个请求失败?任何的想法?谢谢你.

What could be possibly wrong here, why one request pass and another fail? any idea? thank you.

我明白了!,发生此错误只是因为我的第二个请求无法在交换服务器上登录.因为我只提供了一次凭据,所以当findItem响应到来时,与服务器的连接被关闭",并且我的下一个后续请求无法登录.所以我必须再次登录到服务器.

I got it!!, it's error occurs just because of my second request not able to login on the exchange server. since i've provided my credentials only once, So when findItem Response come, connection with the server is 'closed' and my next subsequent request not able to login. so i've to login once again to the server.