Я пытаюсь получить значение из ответа SOAP с помощью PHP. Независимо от того, что я сделал, я не мог получить значение в переменной. Пожалуйста помоги.Как получить значение из ответа SOAP с помощью PHP?
Я использую WordPress's wp_remote_post()
, чтобы отправить форму и получить ответ.
$response = wp_remote_post($url, $args);
$xml = $response['body'];
Вот ответ в SOAP:
<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:body>
<sendtransactionsactionresponse xmlns="http://tempuri.org/">
<sendtransactionsactionresult>113</sendtransactionsactionresult>
</sendtransactionsactionresponse>
</soap:body>
</soap:envelope>
Вот то, что я уже пробовал:
// Din't work
$value = $xml->body->sendtransactionsactionresponse->sendtransactionsactionresult;
// Din't work
$value = $xml['body']['sendtransactionsactionresponse']['sendtransactionsactionresult'];
//Returned an empty Object
simplexml_load_string($xml);
Пытались несколько вещей, но ни один из них не работал. Мне нужно получить значение sendtransactionsactionresult
в переменной для сравнения. Пожалуйста помоги.
Благодаря
EDIT
var-dump
из $response
.
array(5) { ["headers"]=> array(8) { ["connection"]=> string(5) "close" ["date"]=> string(29) "Sat, 26 Sep 2015 18:12:23 GMT" ["server"]=> string(17) "Microsoft-IIS/6.0" ["x-powered-by"]=> string(7) "ASP.NET" ["x-aspnet-version"]=> string(9) "4.0.30319" ["cache-control"]=> string(18) "private, max-age=0" ["content-type"]=> string(35) "application/soap+xml; charset=utf-8" ["content-length"]=> string(3) "401" } ["body"]=> string(401) "
<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:body>
<sendtransactionsactionresponse xmlns="http://tempuri.org/">
<sendtransactionsactionresult>113</sendtransactionsactionresult>
</sendtransactionsactionresponse>
</soap:body>
</soap:envelope>
" ["response"]=> array(2) { ["code"]=> int(200) ["message"]=> string(2) "OK" } ["cookies"]=> array(0) { } ["filename"]=> NULL }
Вы используете SoapClient из PHP? –
Нет. Я использую 'wp_remote_post()' для отправки формы и получения ответа. Подобно этому '$ response = wp_remote_post ($ url, $ args); $ xml = $ response ['body']; ' – Abhik
Вы обновите свой вопрос, чтобы включить эту важную деталь (: –