[英]SOAP XML response using cURL and PHP cisco CUCM API
I'm trying to pull data from a SOAP API (Call manager CISCO) using CURL in PHP with POSTMAN tool like this:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'url',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/11.5">
<soapenv:Header/>
<soapenv:Body>
<ns:getUser sequence="?">
<userid>apiUser</userid>
</ns:getUser>
</soapenv:Body>
</soapenv:Envelope>',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic ..',
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
所以它工作正常,但是當我執行 echo $response 時,我得到了完整的字符串響應,例如:
updatedtestApiapiaddUserTestapiaddUserTestapiaddUserTestapiUser....
而不是我在 var_dump($response) 時得到的 XML 字符串:
'<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:getUserResp.....
基本上我想要做的是訪問我的 XML 值,如 PHP,我嘗試使用 simplexml_load_string 我得到了一個空字符串和 SimpleXMLElement() 並且還得到了一個空的 ZA8CFDE6331BD59EB2AC966F8911C4。
我該如何使用它? 我做錯了什么
您既需要內容類型 header 並接受 http 請求 header
$request[] = 'Content-Type: application/xml';
$request[] = 'Accept: application/xml';
$request[] = 'Authorization: Basic';
CURLOPT_HTTPHEADER => $request
如果沒有Content-Type: application/xml
,Content-Type 將是multipart/form-data
,curl 將嘗試將 JSON 放入 $_POST。
當您指定 application/xml 時,xml 將在請求正文中傳遞。
如果您應該將參數作為表單數據發送,那么您必須將 xml 轉換為數組。
你不需要
CURLOPT_CUSTOMREQUEST => 'POST'
只需使用
CURLOPT_POST => true
如果您想在$response
中查看響應 header ,請添加此內容。 查看響應 header 中的 Content-Type。
CURLOPT_HEADER => true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.