我不能为我的生活弄清楚如何在字符串中保持XML的格式化,即使在回显$data_string
的字符串时,我将XML剥离,只剩下值。
然后我需要能够通过PHP使用该字符串执行CURL请求,但我不确定我是否有正确的设置。
代码:
$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);
测试:
echo $data_string;
结果:
John Doe22seattle