gpt4 book ai didi

c# - HTTP 415 无法处理消息,因为内容类型 'application/json; charset=utf-8' 不是预期的类型 'text/xml; charset=utf-8'

转载 作者:太空狗 更新时间:2023-10-29 21:17:18 28 4
gpt4 key购买 nike

我们有一个在 HTTPS 上运行良好但在 HTTPS 上显示 HTTP 415 错误的网络服务。因此,在 HTTP 下,我们可以毫无问题地发送和接收 JSON 的 POST 请求。当我们在 HTTPS 下尝试相同的操作时,我们收到错误消息,即服务需要 text/xml 而不是 application/json。有什么关于去哪里看的建议吗?

如果重要的话,服务器正在使用自签名证书。

更新了绑定(bind)和行为

 <!-- 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 或 HTTPs 端点。我认为这是问题所在,所以我将其作为“答案”(希望对您有所帮助):

您的端点名称="ProductServiceEndPoint"address="" 它暴露在您的基地址。好的

您的端点名称="ProductServiceSecureEndPoint"address="ProductServiceSecure"bindingConfiguration="SecureBasicHttpBinding"它暴露在基础“base_address]/ProductServiceSecure”。

所以这个端点:

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

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

关于c# - HTTP 415 无法处理消息,因为内容类型 'application/json; charset=utf-8' 不是预期的类型 'text/xml; charset=utf-8',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26625191/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com