0

该脚本会将 xml 内容发布到 url,我需要包含 php GET 变量(例如 $RegionId),请告知如何操作。

 $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 未发布在脚本上,如何在该 xml 内容上使用 GET 或 POST 变量?

4

3 回答 3

1

希望对你有帮助

 $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;
于 2013-09-27T06:53:47.060 回答
0

只需将您的GET变量添加到 url。

 $URL = "http://roomsxmldemo.com/RXLStagingServices/ASMX/XmlService.asmx?var1=val1&var2=val2";
于 2013-09-27T06:31:36.677 回答
0

好吧,只是您可以将您的 xml 内容用双引号括起来并替换必要的变量。

$id = (isset($_GET['id'])) ? $_GET['id'] : '';

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

$id 变量的值将在 xml 内容中。您可以发布此消息。但是,不要忘记在您的 xml 中使用额外的斜杠来屏蔽内部双引号。

于 2013-09-27T06:37:25.287 回答