$ length = strlen($ requestXml); $ ch = curl_init($ serviceUrl);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml; charset=utf-8',
"SOAPAction: \"https://example.com/PMAPI/example/$action\"",
"Content-length: ".strlen($requestXml)
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookieFIle.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookieFIle.txt");
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$xml= simplexml_load_string($output);
print_r($xml);
我得到的输出:
127464347
不是xml格式。但是在View Source中,代码为XML格式。但是,当我将此输出字符串解析为xml解析器时,它没有用。
输出应采用以下格式,我可以在视图源页面中看到该格式。
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><TopUpRequestResponse xmlns="https://dollarphone.com/PMAPI/PinManager"><TopUpRequestResult><responseCode>1</responseCode><TransId>27464347</TransId></TopUpRequestResult></TopUpRequestResponse></soap:Body></soap:Envelope>
当我尝试访问该对象时。错误是“试图获取非对象的属性”。
请有人帮我解决这个问题吗?
我找到了解决方案:我只是从结果中删除了标签。并且有效。
$response1 = str_replace("<soap:Body>","",$output);
$response2 = str_replace("</soap:Body>","",$response1);
// converting to XML
$parser = simplexml_load_string($response2);
谢谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句