How to store SOAP returned value in PHP?
My PHP code using SOAP.
<?php
$client = new SoapClient("http://rscnagahrd/OracleWS/Oracle.asmx?WSDL");
$result = $client->getFoods();
echo $result;
?>
When I try to run the application I get the error:
Catchable fatal error: Object of class stdClass could not be converted to string in C:\\apache\\htdocs\\food.php on line 4
I am doing this so that I could later parse the xml code:
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($result);
$params = $dom->getElementsByTagName('FOOD_ID');
foreach ($params as $param) {
echo $param -> nodeValue, PHP_EOL;
}
The Soapclient
object already has parsed the XML to a response structure ( var_dump($result)
and see). If you want to store it as a string, you'd have make it a string again somehow ( serialize()
if only PHP code needs to read it, json_encode()
if you want to make it more language-agnostic are the usual suspects).
If you need to store the raw xml
response, add array('trace' => true);
as the 2nd parameter in SoapClient
's constructor, and call $client->__getLastRequest();
.
But, if you just want the answer used then & there the $result
response is already parsed for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.