php - 如何使用 php 将 xml soap api 结果打印为 json 或 xml
问题描述
**如何使用 php 将 xml soap api 结果打印为 json 或 xml ** 我以前没有使用过 SOAP API。我想使用 XML 数据请求执行 SOAP API。我试过但没有得到结果。
// The URL to POST to
$url = "https://api.tbotechnology.in/HotelAPI_V7/HotelService.svc";
// The value for the SOAPAction: header
$action = "http://TekTravel/HotelBookingApi/CountryList";
// Get the SOAP data into a string, I am using HEREDOC syntax
// but how you do this is irrelevant, the point is just get the
// body of the request into a string
$mySOAP = <<<EOD
<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:hot="http://TekTravel/HotelBookingApi">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<hot:Credentials UserName="***" Password="***"> </hot:Credentials>
<wsa:Action>http://TekTravel/HotelBookingApi/CountryList</wsa:Action>
<wsa:To>https://api.tbotechnology.in/HotelAPI_V7/HotelService.svc</wsa:To>
</soap:Header>
<soap:Body>
<hot:CountryListRequest/>
</soap:Body>
</soap:Envelope>
EOD;
$headers = array(
'Content-Type: application/soap+xml; charset=UTF-8',
'Content-Length: '.strlen($mySOAP),
'SOAPAction: ' .$action
);
// Build the cURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $mySOAP);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Send the request and check the response
if (($result = curl_exec($ch)) === FALSE) {
die('cURL error: '.curl_error($ch)."<br />\n");
} else {
echo "Success!<br />\n";
echo $result;
}
curl_close($ch);
解决方案
推荐阅读
- hyperledger-fabric - 哪个好的consesus引擎Raft或Kafka
- java - 如何检查文本文件中是否存在单词
- hook - 如何从 MediaWiki SearchAfterNoDirectMatch 挂钩返回文本?
- javascript - 使用类更改单击时的背景颜色
- python-3.x - python 中的 setup.py 显示“ModuleNotFoundError: No module named”尽管它存在并且存在
- asp.net-core - 如何使用 identityserver4 和 asp.netcore 身份进行用户管理
- python - 使用 Python 或 pandas 使用数据集替换另一个数据集中的值
- java - OVERPASS API 中的缩放级别和经纬度之间有什么关系吗?
- javascript - 在 JS 派生类的构造函数中使用 super() 感到困惑
- java - Java 独占全屏模式不断抛出“无效显示模式”