Sending XML data using HTTP POST with PHP

后端 未结 2 2005
感情败类
感情败类 2020-11-28 09:14

I need to send this XML

      

   NO
   1900&         


        
相关标签:
2条回答
  • 2020-11-28 10:04

    Another option would be file_get_contents():

    // $xml_str = your xml
    // $url = target url
    
    $post_data = array('xml' => $xml_str);
    $stream_options = array(
        'http' => array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded' . "\r\n",
            'content' =>  http_build_query($post_data)));
    
    $context  = stream_context_create($stream_options);
    $response = file_get_contents($url, null, $context);
    
    0 讨论(0)
  • 2020-11-28 10:08

    you can use cURL library for posting data: http://www.php.net/curl

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_URL, "http://websiteURL");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "XML=".$xmlcontent."&password=".$password."&etc=etc");
    $content=curl_exec($ch);
    

    where postfield contains XML you need to send - you will need to name the postfield the API service (Clickatell I guess) expects

    0 讨论(0)
提交回复
热议问题