简体   繁体   中英

How to send data to a SOAP Web Service using PHP

I have to send an XML of recent orders to a Web Service using PHP and I'm struggling to figure out how to connect to the web service, authorise and send the required data.

I have the Web Service URL:

https://xxxxx.co.uk/xxxxx/OrderRelay.svc?wsdl

a client code, username and password.

Do I use cURL to send the data or is there another method?

Thanks in advance.

Cheers

if (extension_loaded('soap'))
{
    $Username = "xxxxxx";
    $AccessKey = "xxxxxx";
 
     $url = "https://xxxxx.co.uk/xxxxx/OrderRelay.svc?wsdl";
    
    $options = array(
        'authentication' => SOAP_AUTHENTICATION_BASIC,
        'login' => $Username,
        'password' => $AccessKey,
        'trace' => 1,
        'exception' => 0,
    );
    try
    {
        $client = new SoapClient($url, $options);
                if($client){
                    
$client->Post_Orders(array("unique_Id"=>"$InvoiceNo", "itemNo"=>"$itemNo","_Quantity"=>"$itemQty","waiterNo"=>"$waiterNo","tableId"=>"$tableId","salesSection"=>"$itemSection"));  
                     
                }else{
                    echo"Failed";
                }
    }
    catch (SoapFault $soapFault)
    {
        echo "SOAP REQUEST FAILED :<br>";
    }
}
else
{
    echo "Php SOAP extention is not available";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM