curl的XML发布问题

时间:2018-02-13 07:29:55

标签: php xml curl

<?php
    $xml = '<Msg>
                <Txn>submitsms</Txn>
                <AccountID>myaccountid</AccountID>
                <Password>mypassword</Password>
                <SenderID>ClickSMS</SenderID>
                <Message>this is for testing purpose only</Message>
                <RateCode>1</RateCode>
                <Mobiles>
                    <MobileNo>07123456701</MobileNo>
                </Mobiles>
            </Msg>';


    $url = "service.clicksms.co.uk";
    $headers[] = 'Host: service.clicksms.co.uk';
    $headers[] = 'Content-Type: text/xml';
    $headers[] = 'Content-length: 228';

    //setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml );
    $data = curl_exec($ch);
    curl_close($ch);

    //convert the XML result into array
    $array_data = json_decode(json_encode(simplexml_load_string($data)), true);

    print_r('<pre>');
    print_r($array_data);
    print_r('</pre>');

?>

我遇到问题白色发送xml数据。我有一个api但是当我通过curl发送错误时发送xml数据

  

错误:XML参数缺失或格式错误

因为他们没有在服务器上获得任何xml。

0 个答案:

没有答案