0

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 Answers 3

1

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;
Sign up to request clarification or add additional context in comments.

3 Comments

it's okay with the content in // assigning url..... the problem is that $regionId is not posted by the curl
check it now and let me know
update $xml_data just by this one $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> ';
0

Just add your GET vars to url.

 $URL = "http://roomsxmldemo.com/RXLStagingServices/ASMX/XmlService.asmx?var1=val1&var2=val2";

5 Comments

@user2822230 So rewrite your question, because now it's impossible to understand.
u see xml in $xml_data='xmldata'; the GET or POST vars must be in 'xmldata'
So put it there, it's pretty simple.. $var = 'string '. $var2.' string';
can u pls give the example with the script above?
@user2822230 No, it's to basic and you should do it yourself with provided example.
0

Well, merely you can wrap your xml content in double quotes and substitute necessary variables.

$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>";

Value of $id variable will be in xml content. And you can post this message. But, don't forget to shield inner double quotes with additional slashes in your xml.

2 Comments

im rather new with this things, can u pls give me example with the script above? thanks
the $id is still not posted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.