HTTP 415 无法处理消息,因为内容类型为“application/json;charset=utf-8' 不是预期的类型 'text/xml;字符集=utf-8' [英] HTTP 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'

查看:53
本文介绍了HTTP 415 无法处理消息,因为内容类型为“application/json;charset=utf-8' 不是预期的类型 'text/xml;字符集=utf-8'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个在 HTTPS 上运行良好的网络服务,但在 HTTPS 上显示 HTTP 415 错误.因此,在 HTTP 下,我们可以毫无问题地进行 POST 请求发送和接收 JSON.当我们在 HTTPS 下尝试同样的操作时,我们得到了服务期望 text/xml insteas of application/json 的错误.关于在哪里看的任何建议?

We have a webservice that works fine on HTTPS but shows the HTTP 415 error on HTTPS. So, under HTTP, we can make a POST request sending and receiving JSON without issue. When we try the same under HTTPS we got the error that the service is expecting text/xml insteas of application/json. Any suggestion on where to look?

如果有关系,服务器正在使用自签名证书.

The server is using a self signed certificate if that matters.

更新了绑定和行为

 <!-- Wcf Services Setting -->
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WsHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
        </binding>
        <binding name="SecureWsHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </wsHttpBinding>
      <webHttpBinding>
        <binding name="WebHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
        </binding>
        <binding name="SecureWebHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
          <binding name="webBinding">
              <security mode="Transport">
              </security>
          </binding>
      </webHttpBinding>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IMainService" maxReceivedMessageSize="1048576"></binding>
        <binding name="BasicHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
            <security mode="None">
                <transport clientCredentialType="None" />
            </security>
        </binding>
        <binding name="SecureBasicHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <webHttp DefaultOutgoingResponseFormat="json" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="DvaMfs.WcfService">
        <useRequestHeadersForMetadataAddress>
                    <defaultPorts>
                        <add scheme="https" port="443" />
                    </defaultPorts>
                </useRequestHeadersForMetadataAddress>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

服务看起来像这样

<service name="DvaMfs.WcfService.ProductService" behaviorConfiguration="DvaMfs.WcfService">
    <endpoint name="ProductServiceEndPoint" address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="DvaMfs.WcfService.IProductService" />
    <endpoint name="ProductServiceAjaxEndPoint" address="ajax" binding="webHttpBinding" bindingConfiguration="WebHttpBinding" behaviorConfiguration="AjaxBehavior" contract="DvaMfs.WcfService.IProductService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint name="ProductServiceSecureEndPoint" address="ProductServiceSecure" binding="basicHttpBinding" bindingConfiguration="SecureBasicHttpBinding" contract="DvaMfs.WcfService.IProductService" />
    <endpoint name="ProductServiceAjaxSecureEndPoint" address="ProductServiceSecureajax" binding="webHttpBinding" bindingConfiguration="SecureWebHttpBinding" behaviorConfiguration="AjaxBehavior" contract="DvaMfs.WcfService.IProductService" />
  </service>

更新 2这是失败的端点之一:

<endpoint name="DataServiceSecureEndPoint" address="" binding="basicHttpBinding"
bindingConfiguration="SecureBasicHttpBinding" contract="DvaMfs.WcfService.IDataService" />

推荐答案

WCF 可以有不同的 HTTP 或 HTTP 端点.我认为这是问题所在,所以我将其作为答案"(希望对您有所帮助):

WCF can have different endpoints for HTTP or HTTPs. I think this is the problem, so I will put it as an "answer" (I hope it helps you):

您的端点名称="ProductServiceEndPoint" address="" 它在您的基地址处公开.好的

Your endpoint name="ProductServiceEndPoint" address="" it's exposed at your base address. OK

您的端点名称="ProductServiceSecureEndPoint" address="ProductServiceSecure" bindingConfiguration="SecureBasicHttpBinding" 它在基础base_address]/ProductServiceSecure"中公开.

Your endpoint name="ProductServiceSecureEndPoint" address="ProductServiceSecure" bindingConfiguration="SecureBasicHttpBinding" it's exposed at base "base_address]/ProductServiceSecure".

所以这个端点:

  • 端点名称="DataServiceSecureEndPoint" address="" binding="basicHttpBinding" bindingConfiguration="SecureBasicHttpBinding"

不正确,因为地址可能是ProductServiceSecure"

It's incorrect, because the address may be "ProductServiceSecure"

这篇关于HTTP 415 无法处理消息,因为内容类型为“application/json;charset=utf-8' 不是预期的类型 'text/xml;字符集=utf-8'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆