douxidao3524 2013-09-27 06:27
浏览 37
已采纳

如何使用php GET变量发布带有curl的xml?

the script will post xml content to a url, and i need to include the php GET variables (eg. $RegionId), pls advise how to.

 $RegionId = $_GET["RegionId"];

// xml data 


$xml_data ='<AvailabilitySearch>
  <RegionId xmlns="http://www.reservwire.com/namespace/WebServices/Xml">$RegionId</RegionId>
  <HotelId xmlns="http://www.reservwire.com/namespace/WebServices/Xml">0</HotelId>
  <HotelStayDetails xmlns="http://www.reservwire.com/namespace/WebServices/Xml">
</AvailabilitySearch> 
';

// assigning url and posting with curl 

$URL = "http://roomsxmldemo.com/RXLStagingServices/ASMX/XmlService.asmx";

$ch = curl_init($URL);

............
............
............

$RegionId is not posted on the script, how to use the GET or POST variable on that xml content?

  • 写回答

3条回答 默认 最新

  • dongzhe3171 2013-09-27 06:53
    关注

    Hope this will help You

     $RegionId = $_GET["RegionId"];
    
        // xml data 
    
    
        $xml_data ='<?xml version="1.0" encoding="UTF-8"?><AvailabilitySearch>
          <RegionId xmlns="http://www.reservwire.com/namespace/WebServices/Xml">{$RegionId}</RegionId>
          <HotelId xmlns="http://www.reservwire.com/namespace/WebServices/Xml">0</HotelId>
          <HotelStayDetails xmlns="http://www.reservwire.com/namespace/WebServices/Xml">
        </AvailabilitySearch> 
        ';
    
        // assigning url and posting with curl 
    
        $URL = "http://roomsxmldemo.com/RXLStagingServices/ASMX/XmlService.asmx";
        $headers = array(
        "Content-type: text/xml",
        "Content-length: " . strlen($xml_data),
        "Connection: close",
    );
    
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$UR);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $data = curl_exec($ch); 
    curl_close($ch);
    echo $data;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀