How to write SoapClient request which has basic auth in it? Actually I need to implement SoapClient in Drupal 8. Following XML is Request:

&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.example.com/common/ServiceRequestHeader_v1_0/types" xmlns:typ1="http://www.example.com/customer/CustomerViewRequest_v1_0/types"&gt;
   &lt;soapenv:Header&gt;
      &lt;typ:serviceRequestHeader&gt;
         &lt;applicationCredential&gt;
            &lt;ID&gt;USERNAME&lt;/ID&gt;
            &lt;credential&gt;*****&lt;/credential&gt;
         &lt;/applicationCredential&gt;
         &lt;transactionModel&gt;
            &lt;synchronousRequest&gt;true&lt;/synchronousRequest&gt;
         &lt;/transactionModel&gt;
         &lt;userCredential&gt;
            &lt;ID&gt;RITESH&lt;/ID&gt;
         &lt;/userCredential&gt;
      &lt;/typ:serviceRequestHeader&gt;
   &lt;/soapenv:Header&gt;
   &lt;soapenv:Body&gt;
      &lt;typ1:serviceRequest&gt;
         &lt;requestPreamble&gt;
            &lt;companyCode&gt;IN&lt;/companyCode&gt;
            &lt;customerNumber&gt;12345678&lt;/customerNumber&gt;
         &lt;/requestPreamble&gt;
      &lt;/typ1:serviceRequest&gt;
   &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;


I have tried following code for the same but it is failing and I am not able to make any progress on this:

    $client = new SoapClient('https://example.com:9043/CustomerView_v1_0_vs0',
    array(
        // Stuff for development.
        'trace' =&gt; 1,
        'exceptions' =&gt; true,
        'cache_wsdl' =&gt; WSDL_CACHE_NONE,
        'features' =&gt; SOAP_SINGLE_ELEMENT_ARRAYS,

        // Auth credentials for the SOAP request.
        'ID' =&gt; 'USERNAME',
        'credential' =&gt; 'Password',


    )
);
    dump($client); die;


Its giving below error:

SOAP-ERROR: Parsing WSDL: Couldn&amp;#039;t load


Can anyone suggest some way on this ?
I believe the answer is nearly there for you, but ID and credential are the wrong keys in the options array.

       'login' =&gt; 'USERNAME',
       'password' =&gt; 'Password',


I suggest that you put the username and password into conf in your settings.php file so they are not in your codebase nor your site configuration data. See How secure are variable_get and variable_set? for details on how to securely have credentials in Drupal's config system.