当我调用方法时,我正试图通过Soap连接WS并遇到内容类型错误:内容类型'text / xml; charset = utf-8'不是预期的类型'application / soap + xml;字符集= UTF-8'
以下是我的代码,减少了参数数量和隐藏网址,用户和密码。
当我调用ClientRegist()函数时发生错误。我确信我必须以不同的方式传递$ params,但无法在任何地方找到一个例子。
$url = 'http://---';
$ctx_opts = array(
'http' => array(
'header' => 'Content-Type: application/soap+xml'
),
'username' => '---',
'password' => '---',
'trace' => true,
'exceptions' => true
);
$ctx = stream_context_create($ctx_opts);
$client = new SoapClient($url, array('stream_context' => $ctx));
$params = array(
'Cardnumber' => $number,
'Name' => $name
);
try {
$client = new SoapClient($url, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->ClientRegist($params);
}
catch (Exception $e) {
echo "Error!<br>";
echo $e -> getMessage ().'<br>';
echo 'Last response: '. $client->__getLastResponse();
}
var_dump($response);
答案 0 :(得分:2)
尝试SOAP 1.2版。它的默认Content-Type是application / soap + xml
<?php
// ...
$client = new SoapClient(
$url,
array(
'soap_version' => SOAP_1_2, // !!!!!!!
'stream_context' => $ctx
)
);