php 内容类型 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; 字符集=utf-8'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5405874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:17:35  来源:igfitidea点击:

content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'

phpsoap

提问by Iliya

I've been trying for a long time to send right request to soap server. I'm keep getting error message.

我一直在尝试向soap服务器发送正确的请求。我不断收到错误消息。

Here is my xml

这是我的 xml

GET LAST REQUEST (newlines added):

获取最后一个请求(添加换行符):

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body><ns1:TestData1><ns1:iVal>1</ns1:iVal></ns1:TestData1></SOAP-ENV:Body>
</SOAP-ENV:Envelope>

GET LAST RESPONSE :

得到最后的回应:

REQUEST HEADERS:

请求头:

POST /DPWebService/CardsService.svc/ICardsService HTTP/1.1
Host: d67v7tg1
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.9-1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/ICardsService/TestData1"
Content-Length: 254

Here is the response.

这是回应。

object(SoapFault)#2 (8) { 
["message:protected"]=> string(142) "Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'." 
["string:private"]=> string(0) "" 
["code:protected"]=> int(0) 
["file:protected"]=> string(32) "C:\localhost\www\test5\index.php" 
["line:protected"]=> int(208) 
["trace:private"]=> array(3) { 
    [0]=> array(4) { 
        ["function"]=> string(11) "__doRequest" 
        ["class"]=> string(10) "SoapClient" 
        ["type"]=> string(2) "->" 
        ["args"]=> array(5) { 
            [0]=> string(254) " 1 " 
            [1]=> string(59) "http://d67v7tg1/DPWebService/CardsService.svc/ICardsService" 
            [2]=> string(42) "http://tempuri.org/ICardsService/TestData1" 
            [3]=> int(1) 
            [4]=> int(0) 
        }
    } 
    [1]=> array(4) { 
        ["function"]=> string(6) "__call" 
        ["class"]=> string(10) "SoapClient" 
        ["type"]=> string(2) "->" 
        ["args"]=> array(2) { 
            [0]=> string(9) "TestData1" 
            [1]=> array(1) { 
                [0]=> array(2) { 
                    ["iVal"]=> int(1) 
                    ["strVal"]=> string(5) "Proba" 
                } 
            } 
        } 
    } 
    [2]=> array(6) { 
        ["file"]=> string(32) "C:\localhost\www\test5\index.php" 
        ["line"]=> int(208) 
        ["function"]=> string(9) "TestData1" 
        ["class"]=> string(10) "SoapClient" 
        ["type"]=> string(2) "->" 
        ["args"]=> array(1) { 
            [0]=> array(2) { 
                ["iVal"]=> int(1) 
                ["strVal"]=> string(5) "Proba" 
            } 
        } 
    } 
} 
["faultstring"]=> string(142) "Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'." 
["faultcode"]=> string(4) "HTTP" 
} 

GET LAST RESPONSE :

得到最后的回应:

REQUEST HEADERS:

请求头:

POST /DPWebService/CardsService.svc/ICardsService HTTP/1.1
Host: d67v7tg1
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.9-1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/ICardsService/TestData1"
Content-Length: 254

回答by Ryan Williams

This appears to have fixed it for me.

这似乎为我修复了它。

$client = new SoapClient($this->url, array('soap_version' => SOAP_1_2));

回答by Charles

PHP's native SOAP extension is an undebuggable binary blob of horrors.

PHP 的原生 SOAP 扩展是一个不可调试的二进制大块。

According to this comment in the PHP manual, it is hard-coded to send SOAP requests with the MIME content type application/soap+xml.

根据 PHP 手册中的此注释,发送具有 MIME 内容类型的 SOAP 请求是硬编码的application/soap+xml

Your SOAP server seems to reject this content type, expecting only text/xml.

您的 SOAP 服务器似乎拒绝这种内容类型,只需要text/xml.

According to this SOAP 1.2 standard document, section 7.1.4 on SOAP over HTTP:

根据此 SOAP 1.2 标准文档,关于 SOAP over HTTP 的第 7.1.4 节:

Conforming implementations of this binding:

  1. MUSTbe capable of sending and receiving messages serialized using media type "application/soap+xml" whose proper use and parameters are described in A. The application/soap+xml Media Type.

符合此绑定的实现:

  1. 必须能够发送和接收使用媒体类型“application/soap+xml”序列化的消息,其正确使用和参数在A. the application/soap+xml Media Type 中描述

The SOAP server you are using is not complaint with the 1.2 standard.

您使用的 SOAP 服务器不符合 1.2 标准。

(For the record, this is the first time I've ever, ever seen anyone with a question about the PHP SOAP extension where the problem wasn'twith the extension itself!)

(作为记录,这是我第一次看到有人对 PHP SOAP 扩展提出问题,而问题在于扩展本身!)