我正在尝试使用PHP中的curl发送和接收XML。我想试试 通过curl请求连接salesforce。 但我面临的问题是响应是单一的 string,而salesforce以XML格式返回响应。
我发送XML请求登录saleforce。 这是我的剧本
$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!
答案 0 :(得分:0)
尝试使用此代码
$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);
答案 1 :(得分:0)
我认为你应该在$ data上转义版本和编码 例如
$data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".$whateverXml;