Send XML data to a server using PHP

126 views Asked by At

Can someone please assist me to send xml data to a server using php ?

here is information

<?xml version="1.0" encoding="UTF-8"?>
    <SOAPENV:Envelope 
    xmlns:SOAPENV="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:SOAPENC="http://www.w3.org/2003/05/soap-encoding" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <SOAPENV:Body>
            <JobRequest xmlns="http://81.105.223.86:80/cni">
              <SourceSystem>KVCARS</SourceSystem>
              <SourcePassword>Ketchup96</SourcePassword>
              <SourceJobID>*KV001*</SourceJobID>
              <SourceAccount>CORDIC</SourceAccount>
              <TargetSystem>TARGET1</TargetSystem>
              <Lifetime>60</Lifetime>
              <DriverNotes>Please wait at reception.</DriverNotes>
              <OperatorNotes>Test job for CNI.</OperatorNotes>
              <BookerName>Jane</BookerName>
              <BookerPhone>01954233255</BookerPhone>
              <BookerEmail>[email protected]</BookerEmail>
              <StopList>
                <Stop>
                  <Order>1</Order>
                  <Passenger>Fara Arani</Passenger>
                  <Address>Cordic Ltd, 1 Rowles Way, Swavesey, Cambridge</Address>
                  <Postcode>CB24 4UG</Postcode>
                  <ContactPhone>01954233255</ContactPhone>
                  <ContactOnArrive>Ring</ContactOnArrive>
                </Stop>
                <Stop>
                  <Order>2</Order>
                  <Address>Heathrow Airport, Terminal 4</Address>
                  <Postcode>TW6 3GA</Postcode>
                </Stop>
              </StopList>
              <AttributeList>
                <Attribute>Executive</Attribute>
                <Attribute>Professional</Attribute>
              </AttributeList>
            </JobRequest>
          </SOAPENV:Body>
        </SOAPENV:Envelope>

Here are the details you should use for sending messages to a test version of the gateway that you can use to develop your system:

URL= http://81.105.223.86:80/cni
SourceSystem= KVCARS
SourcePassword= Ketchup96

You can use any SourceAccount name, except blank. If you use SourceJobType=Account, you will book an account job, anything else is mapped to Cash.

There are test target system called TARGET1 that is configured to receive jobs. target systems has a simulator running that will simulates a fleet of vehicles (one of around 100 vehicles the other around 50). The simulated vehicles should accept and progress jobs sent to them.

Here are the details:

Target1 URL= http://86.17.13.109:81/Webbooker
Account= *KV001*   (including the asterisks)
User= KVCARS
Password= Ketchup96
1

There are 1 answers

0
Bruce On

$url = "http://86.17.13.109:81/Webbooker";

    //setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);

// Following line is compulsary to add as it is: curl_setopt($ch, CURLOPT_POSTFIELDS, "xmlRequest=" . $input_xml); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300); $data = curl_exec($ch); curl_close($ch);

    //convert the XML result into array
    $array_data = json_decode(json_encode(simplexml_load_string($data)), true);

    print_r('<pre>');
    print_r($array_data);
    print_r('</pre>');

Reference Send XML data to a server using PHP