2014-04-23 175 views
0

我不能为了我的生活弄清楚如何在字符串中保留XML的格式,即使当回显字符串$data_string我得到的XML被剥离,只剩下值。用PHP 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 
+0

“我不能为我的生命” :)))))) –

+0

尝试检查你的页面”的源代码,以逃避HTML字符重新进入,通常CTRL + U –

回答

1

你应该确保你是呼应的页面也使用MIME类型text/xml

另一种方式我能想到的,是用htmlentities()

+0

htmlentities似乎工作,有没有办法漂亮打印它呢? – Andrew

+0

这似乎很有希望:http://stackoverflow.com/questions/8615422/php-xml-how-to-output-nice-format#answer-8615485 – sircapsalot

+0

谢谢,这对我来说! – Andrew