PHP https post XML data with cURL

前端 未结 3 831
刺人心
刺人心 2021-01-01 01:49

I\'m trying to send a HTTPS POST request with XML data to a server using PHP.

Anything sends to the server requires authentication therefore I\'ll use cURL.

相关标签:
3条回答
  • 2021-01-01 01:58

    You have to do, in you original code:

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields['data']);
    

    or

    curl_setopt($ch, CURLOPT_POSTFIELDS, '<n1:asset xmlns:n1="http://.....com/"><title>AAAA</title><fileName>http://192.168.11.30:8080/xxx.html</fileName><description>AAAA_desc</description><fileType>HTML</fileType></n1:asset>');
    

    I mean that you have to send the XML directly.

    0 讨论(0)
  • 2021-01-01 02:10

    Perhaps you could try text/xml instead of application/xml?

    0 讨论(0)
  • 2021-01-01 02:14

    I solve with

    $xml = $this->getXml();
    $url = $this->getUrl();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                           'Content-type: application/xml', 
                                           'Content-length: ' . strlen($xml)
                                         ));
    $output = curl_exec($ch);
    curl_close($ch);
    
    0 讨论(0)
提交回复
热议问题