PHP卷曲请求与XML

时间:2014-04-23 20:45:37

标签: php xml curl

我不能为我的生活弄清楚如何在字符串中保持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

1 个答案:

答案 0 :(得分:1)

您应该确保您回复的页面也使用MIME类型text/xml

我能想到的另一种方法是使用htmlentities()

来转义html字符
相关问题