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条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统