简体   繁体   English

如何从PHP中的CURL XML请求接收XML格式的响应

[英]How to Receive response in XML format from CURL XML Request in PHP

I am trying to Send and receive the XML using curl in PHP. 我正在尝试使用PHP中的curl发送和接收XML。 I want to try to connect the salesforce via curl request. 我想尝试通过curl请求连接Salesforce。 But the problem which I am facing is that the response is a single string, whereas salesforce returns the response in XML. 但是我面临的问题是响应是单个字符串,而salesforce以XML返回响应。

I am sending XML request to login into the saleforce. 我正在发送XML请求以登录到salesforce。 Here is my script 这是我的剧本

$data='<?xml version="1.0" encoding="utf-8" ?>.....'


$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_URL, "https://login.salesforce.com/services/Soap/u/29.0");
curl_setopt($tuCurl, CURLOPT_PORT , 443);
/*curl_setopt($tuCurl, CURLOPT_VERBOSE,false);
curl_setopt($tuCurl, CURLOPT_HEADER, true);*/
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($tuCurl, CURLOPT_POST, true); 
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $data);  
/*curl_setopt($tuCurl, CURLOPT_FOLLOWLOCATION, TRUE);*/
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml; 
charset=UTF- 8","SOAPAction: login", "Content-length: ".strlen($data)));
$tuData = curl_exec($tuCurl);
curl_close($tuCurl);
echo $tuData;

Thanks for any help!

Try with this code 尝试使用此代码

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close ($ch);

我认为您应该在$ data上转义版本和编码,例如

$data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".$whateverXml;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM