[英]PHP Curl Request with XML
I can not for the life of me figure out how to keep the formatting of XML in a string, even when echoing the string of $data_string
I get the XML stripped out and only the values remain. 我一生都无法弄清楚如何将XML的格式设置为字符串,即使在回显
$data_string
字符串时,我也会剥离XML,仅保留值。
Then I need to be able to do a CURL request via PHP with that string, I'm not sure if I have the right setup for that though. 然后,我需要能够使用该字符串通过PHP发出CURL请求,但是我不确定是否为此设置了正确的设置。
Code: 码:
$data_string = '<test><name>John Doe</name><age>22</age><city>seattle</age></test>';
$curl = curl_init($baseUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "xmlRequest=" . $data_string);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Length: " . strlen($data_string),
"X-DocuSign-Authentication: $header",
"Content-Type: text/xml",
"Accept: text/xml" )
);
$response = curl_exec($curl);
Test: 测试:
echo $data_string;
Result: 结果:
John Doe22seattle
You should make sure that the page you are echoing is ALSO using the MIME type text/xml
. 您应该使用MIME类型
text/xml
来确保要回显的页面也是。
Another way i can think of, is to escape the html characters using htmlentities() 我能想到的另一种方法是使用htmlentities()转义html字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.