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

标签 c++ web-services soap exchangewebservices gsoap

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

错误 401 故障:SOAP-ENV:Server[无子代码] “HTTP 错误” 详细信息:HTTP/1.1 401 未经授权

但是我的登录凭据是正确的,因为这些凭据与 findItem 请求和响应配合良好,但是当 GetItem 请求发送到服务器时,它会出现上述错误。我的凭据如下:

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

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

最佳答案

我知道了!!,它的错误发生只是因为我的第二个请求无法登录交换服务器。因为我只提供了一次凭据,所以当 findItem 响应到来时,与服务器的连接“关闭”并且我的下一个后续请求无法登录。所以我必须再次登录服务器。

关于c++ - 发送 GetItem 请求时出现 HTTP 401 未经授权的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32746729/

相关文章:

php - 将简单的 C++ 移植到 PHP 代码

在同一类的另一个方法中调用 C++ GoogleMock 模拟方法

WCF 客户端在 HTTP POST 消息中不包含 XML 声明

c# - 重命名 WCF 服务时出错

web-services - URL 末尾不带 WSDL 的 SOAP Web 服务

python - 如何从 zeep python 库解析 soap Fault.detail(lxml.etree._Element)

使用 ICU 和 Nana GUI 库的 C++ - 字符串转换?

c++ - const 函数,但我可以 "modify"类

java - 如何从 WS 响应中提取 SOAP header

java - 加入 SAAJ 和 JAXB