我正在尝试通过Soap连接WS并在调用方法时遇到内容类型错误: content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=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);
1 回答
尝试SOAP 1.2版 . 它的默认Content-Type是application / soap xml