cURL将XML发送到webservice。需要不同的编码

时间:2012-12-17 20:01:45

标签: web-services soap curl

有没有办法设置cURL来发送带有&lt;&lt;而不是<>

的XML
    $xml_data = '
    <Shipping_Address>
    <Province>BC</Province>
    <Country>Canada</Country>
    <PostalCode>V6P 5T2</PostalCode>
    <Phone>604-561-7977</Phone>
    </Shipping_Address>';

$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml','charset=ISO-8859-1'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
var_dump($output);

1 个答案:

答案 0 :(得分:0)

如果web服务期待XML,这似乎很奇怪。但如果是,您应该可以通过调用htmlentities()

来实现
$xml_data = htmlentities('
    <Shipping_Address>
    <Province>BC</Province>
    <Country>Canada</Country>
    <PostalCode>V6P 5T2</PostalCode>
    <Phone>604-561-7977</Phone>
    </Shipping_Address>');