【发布时间】:2017-03-22 18:35:36
【问题描述】:
我正在尝试通过 Soap 与 WS 连接,并在调用该方法时遇到内容类型错误:content type 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'
以下是我的代码,减少了参数数量并隐藏了 url、用户和密码。
当我调用 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);
【问题讨论】:
标签: php web-services soap header content-type