[英]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: 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;
So it is working fine but i get a full string response when i do echo $response like:所以它工作正常,但是当我执行 echo $response 时,我得到了完整的字符串响应,例如:
updatedtestApiapiaddUserTestapiaddUserTestapiaddUserTestapiUser....
Instead of the XML string that i got when i var_dump($response):而不是我在 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.....
Basically what i want to do is to access my XML values like in PHP, i tried using simplexml_load_string i got an empty string and also SimpleXMLElement() and also got an empty object..基本上我想要做的是访问我的 XML 值,如 PHP,我尝试使用 simplexml_load_string 我得到了一个空字符串和 SimpleXMLElement() 并且还得到了一个空的 ZA8CFDE6331BD59EB2AC966F8911C4。
How can i work with it?我该如何使用它? what i am doing wrong我做错了什么
You need both content-type header and accept http request header您既需要内容类型 header 并接受 http 请求 header
$request[] = 'Content-Type: application/xml';
$request[] = 'Accept: application/xml';
$request[] = 'Authorization: Basic';
CURLOPT_HTTPHEADER => $request
With out the Content-Type: application/xml
the Content-Type will be multipart/form-data
and curl will attempt to put the JSON in the $_POST.如果没有Content-Type: application/xml
,Content-Type 将是multipart/form-data
,curl 将尝试将 JSON 放入 $_POST。
When you specify application/xml the xml will be passed in the request body.当您指定 application/xml 时,xml 将在请求正文中传递。
If you are supposed to send the parameters as form data then you must convert the xml to an array.如果您应该将参数作为表单数据发送,那么您必须将 xml 转换为数组。
You do not need你不需要
CURLOPT_CUSTOMREQUEST => 'POST'
Just use只需使用
CURLOPT_POST => true
If you want to see the response header in your $response
, add this.如果您想在$response
中查看响应 header ,请添加此内容。 Look at the Content-Type in the response header.查看响应 header 中的 Content-Type。
CURLOPT_HEADER => true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.