配置SOAP API XML
我想配置与PHP肥皂的API,将XML下面是用于API,但它没有响应,请帮我恢复这个问题配置SOAP API XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<userName>username</userName>
<password>password</password>
<agentCode>code</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>
的下方显示我用来调用xml的php代码。但我没有得到任何回应我的PHP代码,但该XML是正确的,我已经问他们告诉我的XML提供者是正确的,但我的PHP代码是不正确的。我不我做什么来解决这个问题:(
<?php
$soapUrl = "http://testapi.roombookpro.com/en/soap/index?wsdl"; // asmx URL of WSDL
$soapUser = "username"; // username
$soapPassword = "password"; // password
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<!-- You may enter the following 4 items in any order -->
<userName>username</userName>
<password>password</password>
<agentCode>agentcode</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>'; // data from the form, e.g. some ID number
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache"
"SOAPAction: http://testapi.roombookpro.com/en/soap/index#getCountries",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
var_dump($parser);
echo $parser;
// user $parser to get your data out of XML response and to display it.
?>
在你的代码,你的要求指向下方WSDL链接,
http://testapi.roombookpro.com/en/soap/index?wsdl
而这就是为什么你没有得到的SOAP响应,而你得到定义。
你应该使用下列URL肥皂拿到SOAP响应,
http://testapi.roombookpro.com/en/soap/index
编辑: 并获得XML响应(如串):
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
得到尽可能SimpleXMLElement对象:
$xml = simplexml_load_string($response);
foreach ($xml->xpath('//ns2:Soap_Model_SOAP_Location_Country') as $item)
{
print_r($item);
//to access individual elements
// echo $item->id ;
// echo $item ->code;
// echo $item->name;
// echo "\n";
}
其给出的XML对象的数组:
SimpleXMLElement Object
(
[id] => 252
[code] => ZW
[name] => Zimbabwe
)
我已经改变了这一点,但现在我面临另一个问题,它显示在HTML而不是在XML。 –
它不工作,我用** htmlentities()** 但现在我不能从xml –
价值当我使用** simplexml_load_string()**显示时区错误 –
你得到任何HTTP错误? –
我不知道如何配置这 –
你试过[这](https://www.soapui.org/getting-started/your-first-soapui-project.html) –