我正在尝试进行soap调用,它返回一个“坏请求”错误。
示例调用如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://centric.eu/services/CS/Trade/Standard/WS/" xmlns:cen="http://schemas.datacontract.org/2004/07/Centric.CS.Trade.Standard.WS.StockService.Contract.Request">
<soapenv:Header>
<ws:Security soapenv:mustUnderstand="1" xmlns:ws="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<ws:UsernameToken>
<ws:Username>username</ws:Username>
<ws:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</ws:Password>
</ws:UsernameToken>
</ws:Security>
</soapenv:Header>
<soapenv:Body>
<ws:GetStock>
<ws:request>
<cen:StockRequests>
<!--Zero or more repetitions:-->
<cen:StockRequest>
<cen:CustomerNo>123</cen:CustomerNo>
<cen:Division>AGU_NL</cen:Division>
<cen:Item>113504</cen:Item>
<cen:Language>NL</cen:Language>
<cen:Login>123</cen:Login>
</cen:StockRequest>
</cen:StockRequests>
</ws:request>
</ws:GetStock>
</soapenv:Body>
</soapenv:Envelope>我使用以下代码:
$soapclient = new \SoapClient($url, array(
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 9,
'trace' => true,
'exceptions' => 1,
'cache_wsdl' => 1,
));
$xml = '
<ws:Security soapenv:mustUnderstand="1" xmlns:ws="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<ws:UsernameToken>
<ws:Username>'.$username.'</ws:Username>
<ws:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</ws:Password>
</ws:UsernameToken>
</ws:Security>
';
$soapheader = new \SoapHeader(
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
'Security',
new \SoapVar($xml, XSD_ANYXML),
true);
$soapclient->__setSoapHeaders($soapheader);
try {
$soapclient->__soapCall('GetStock',
array(
'CustomerNo' => 123,
'Division' => 'AGU_NL',
'Item' => '113504',
'Language' => 'NL',
'Login' => '123',
)
);
} catch(\SoapFault $e) {
echo '<pre>';
print_r($e->getMessage());
echo '</pre>';
}我得到的响应是:错误代码: HTTP,故障字符串:糟糕的请求我不完全确定我是否创建了请求并正确调用了该方法。
如有任何帮助,将不胜感激。
谢谢
发布于 2020-01-17 12:53:43
你收到坏请求的原因是你没有很好地格式化你的请求,如果你的请求之间没有空格的话,试着去做
https://stackoverflow.com/questions/59787601
复制相似问题