我尝试使用尽可能少的代码对服务器进行soap调用。但是,我有一个问题是我自己进行身份验证(该呼叫没有必要的标头)。这是我的代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: text/html; charset=utf-8');
$data = array('Username' => 'someusername', 'Userpass' => 'somepass');
try
{
$client = new SoapClient(null, array(
"location" => "http://relaxdays.plentymarkets-x1.com/plenty/api/soap/version115/?xml",
"uri" => "http://relaxdays.plentymarkets-x1.com/plenty/api/soap/version115/",
"trace" => true,
"soap_version" => SOAP_1_1,
"exceptions" => false
));
$response = $client->__soapCall("PlentySoapRequest_GetAuthentificationToken", $data);
}
catch (Exception $e)
{
echo "Error!";
echo $e -> getMessage();
echo '<br/><br/>Last response:<button type="button" onclick="if(document.getElementById(\'spoiler1\').style.display==\'none\') {document.getElementById(\'spoiler1\') .style.display=\'\'}else{document.getElementById(\'spoiler1\') .style.display=\'none\'}">Show/Hide</button><div id="spoiler1" style="display:none; font-family:monospace;">'. htmlspecialchars($client->__getLastResponse()).'</div>';
}
echo '<br/><br/>Last request:<button type="button" onclick="if(document.getElementById(\'spoiler2\').style.display==\'none\') {document.getElementById(\'spoiler2\') .style.display=\'\'}else{document.getElementById(\'spoiler2\') .style.display=\'none\'}">Show/Hide</button><div id="spoiler2" style="display:none; font-family:monospace;">'. htmlspecialchars($client->__getLastRequest()).'</div>';
echo '<br/><br/>Response:<button type="button" onclick="if(document.getElementById(\'spoiler3\').style.display==\'none\') {document.getElementById(\'spoiler3\') .style.display=\'\'}else{document.getElementById(\'spoiler3\') .style.display=\'none\'}">Show/Hide</button><div id="spoiler3" style="display:none; font-family:monospace;">'. htmlspecialchars($response).'</div>';
?>
然而,无论我尝试什么,它似乎都不起作用。我发现的最远的是这个错误:
SoapFault exception: [VersionMismatch] Wrong Version in /var/www/htdocs/plentyimport/tester.php:18
Stack trace: #0 /var/www/htdocs/plentyimport/tester.php(18): SoapClient->__soapCall('PlentySoapReque...', Array) #1 {main}
我已经尝试过使用"soap_version" => SOAP_1_2
,或者将Soap-URL切换到不同版本(例如/version112/
),但错误只是不想消失。
任何帮助都将不胜感激。
非常感谢
virhonestum
答案 0 :(得分:1)
您必须将SOAP的定义作为第一个参数传递,如下所示:
$client = new SoapClient('http://relaxdays.plentymarkets-x1.com/plenty/api/soap/version115/?xml');
我已经删除了其他参数,因为这些参数不是必需的。
应该拨打operation
,在这种情况下应该这样:
$response = $client->__soapCall("GetAuthentificationToken", $data);
最后,数据应包含结构PlentySoapRequest_GetAuthentificationToken
,如下所示:
$data = [
'PlentySoapRequest_GetAuthentificationToken' => [
'Username' => 'someusername',
'Userpass' => 'somepassword'
]
];
注意:我不会将此作为完整答案发布。我不知道SOAP,也无法解释什么是错误的以及我如何解决它,只发布这个以帮助作者走出这个阶段。