简体   繁体   English

EWS HttpHeader内容类型

[英]EWS HttpHeader Content-type

I've followed Microsoft's Get started with EWS Managed API client applications tutorial, in an effort to build an application that will get specific items from a mailbox on an Exchange server. 我遵循了Microsoft的EWS托管API客户端应用程序入门教程,以构建一个可从Exchange服务器上的邮箱中获取特定项目的应用程序。

It seems that after the initial auto-discover operations succeed, no matter what kind of request I send through the API, I get a response back containing the following: 似乎在初始自动发现操作成功之后,无论我通过API发送什么样的请求,我都收到包含以下内容的响应:

HTTP/1.1 415 Cannot process the message because the content type 'text/plain; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.

With Microsoft.Exchange.WebServices.Data.ExchangeService.TraceEnabled = true , the trace of a typical request looks like this (this one is generated by calling Folder.Bind(service, "IT", propSet) ): 使用Microsoft.Exchange.WebServices.Data.ExchangeService.TraceEnabled = true ,典型请求的跟踪如下所示(此请求是通过调用Folder.Bind(service, "IT", propSet) ):

<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="EwsRequest" Tid="1" Time="2019-03-01 14:42:02Z" Version="15.0.913.15">
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2013" />
    </soap:Header>
    <soap:Body>
      <m:GetFolder>
        <m:FolderShape>
          <t:BaseShape>IdOnly</t:BaseShape>
        </m:FolderShape>
        <m:FolderIds>
          <t:FolderId Id="IT" />
        </m:FolderIds>
      </m:GetFolder>
    </soap:Body>
  </soap:Envelope>
</Trace>

It looks like the Content-Type header is missing altogether, so the server sees the request as text/plain; charset=utf-8 看起来Content-Type标头完全丢失了,因此服务器将请求视为text/plain; charset=utf-8 text/plain; charset=utf-8 . text/plain; charset=utf-8 It shouldn't be a problem to add Content-Type: text/xml; charset=utf-8 添加Content-Type: text/xml; charset=utf-8应该不是问题Content-Type: text/xml; charset=utf-8 Content-Type: text/xml; charset=utf-8 to requests that the ExchangeService object makes, but the member Dictionary HttpHeaders is not settable (see the interface in ExchangeServiceBase ). Content-Type: text/xml; charset=utf-8来请求ExchangeService对象发出的请求,但成员Dictionary HttpHeaders成员是不可设置的(请参阅ExchangeServiceBase中的接口)。

Any idea how I can either send the server an acceptable request with the EWS Managed API, or configure the target Exchange server so that it accepts the requests I'm sending? 知道如何通过EWS托管API向服务器发送可接受的请求,或者配置目标Exchange服务器以使其接受我发送的请求吗? I've come across lots of related SO questions, but none with an actual answer to this problem. 我遇到了很多相关的SO问题,但是没有一个问题有实际答案。

I was getting the same error and the only clue I could find was this thread. 我遇到了同样的错误,我唯一能找到的线索就是这个线程。

I eventually fixed it by switching to Microsoft.Exchange.WebServices.NETStandard -v 1.1.3 (from -v 2.0.0-beta1). 我最终通过切换到Microsoft.Exchange.WebServices.NETStandard -v 1.1.3(从-v 2.0.0-beta1)来解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM