【发布时间】:2019-05-28 07:36:39
【问题描述】:
在实现以下代码后,我收到“无法处理消息,因为内容类型 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'”。请帮助调查此问题。
我尝试使用 SOAP UI 提供相同的服务并取得了成功。将 SOAP 版本更改为 1.1 后,我也收到了与 SOAP UI 相同的消息。
示例代码
<?php
$context = stream_context_create([
'ssl' => [
'soap_version' => SOAP_1_2,
'verify_peer' => false,
'verify_peer_name' => false,
'connection_timeout' => 1
]
]);
$requestParams = '<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<CustomHeader xmlns="http://schemas.test.com/CustomHeader">
</CustomHeader>
</s:Header>
<s:Body>
</s:Body>
</s:Envelope>';
$client = new SoapClient('https://myservice.svc?singlewsdl', array('stream_context' => $context));
$client->__setLocation('https://myservice.svc');
$response = $client->__soapCall('mymethod', array($requestParams));
?>
【问题讨论】: