使用基本身份验证来处理PHP SOAP请求

I'm trying to find a way to set up a PHP file which will send SOAP request with basic username and pass authentication to the provider and then take the response and write it to the file in the same folder.

It should rewrite or update the file on every call.

The link with details: https://www.ct4partners.com/ws/ctproductsinstock.asmx

Simple example below:

<?php
/* Method GetCTProductGroups
 <GetCTProductGroups xmlns="http://www.ct4partners.com/B2B"> <== 1. method 
      <username>string</username>  <===  2. param 
      <password>string</password>   <=== 2. param
    </GetCTProductGroups>
 */

$urlToWsdl = 'https://www.ct4partners.com/ws/ctproductsinstock.asmx?wsdl';

$client = new SoapClient($urlToWsdl);

$request = array(
    'username' => 'login', //2. param
    'password' => 'pass'    //2. param
);

$client->GetCTProductGroups($request); //1. call method

$xml = $client->__getLastResponse(); // Get XML

//if response not empty (You must provide real login details / real data param)
if(isset($xml))
{
    $dom = new DOMDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->loadXML(
            $xml,
            LIBXML_HTML_NOIMPLIED | 
            LIBXML_HTML_NODEFDTD |  
            LIBXML_NOERROR |        
            LIBXML_NOWARNING        
        );

    //Save XML as a file
    $dom->save('response.xml');
}