0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • The purpose of this site is not to do your research for examples for you. Please go read [ask]. – 04FS Feb 14 '19 at 11:48
  • Thanks for your comment, I appreciate it. I wasn't looking for an examples perse but more the point in the right direction. I went through all the related problems here and couldn't find anything that could be applied to my case. – Marko Kojic Feb 14 '19 at 11:58
  • Try https://stackoverflow.com/questions/10219463/wsdl-to-php-with-basic-auth for some possible approaches. – 04FS Feb 14 '19 at 13:04

1 Answers1

0

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');
}
websky
  • 3,047
  • 1
  • 33
  • 31
  • Thanks a lot for your answer. It seems that something is missing as I'm getting "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://www.ct4partners.com/ws/ctproductsinstock.asmx.wsdl' : failed to load external entity "https://www.ct4partners.com/ws/ctproductsinstock.asmx.wsdl" I checked and try with couple of solutions here but with no luck: https://stackoverflow.com/questions/21861077/soap-error-parsing-wsdl-couldnt-load-from-but-works-on-wamp – Marko Kojic Mar 01 '19 at 10:49
  • What is your php version? I tested on version 7.3. – websky Mar 04 '19 at 05:22