Problems with SOAP Session

Discussion in 'General' started by pyte, Mar 25, 2022.

  1. pyte

    pyte Well-Known Member HowtoForge Supporter

    I've got an Problem with a soap session. I am trying to import a lot of DNS Data into ISPConfig. My script is working as far as i could test it, however something seems to be wrong with the soap connection. Here is the relevant part of the code:
    Code:
    function create_soap_session() {
        // login data for the soap interface
        $username = 'userXXXXXXXX';
        $password = 'passXXXXXXXX';
        $soap_location = 'https://hosting.xxx.com/index.php';
        $soap_uri = 'https://hosting.xxx.com/remote/';
        
        $client = new SoapClient(null, array('location' => $soap_location,
                                             'uri'      => $soap_uri));
                                        
        try {
            if($session_id = $client->login($username, $password)) {
                echo 'Logged successfull. Session ID:'.$session_id.'<br />';
            }
        } catch (SoapFault $e) {
        echo $client->__getLastResponse();
        die('SOAP Error: '.$e->getMessage());
        }
    
    }
    When i run the script i always get the following error:

    Code:
    SOAP Error: looks like we got no XML document
    I've already searched the web for fixes but they seem to be related to older versions of php. I've checked the hosting.xxx.com/remote/ Website and it shows a blank page, as it should it seems. I've also check the access.log
    Code:
    XXX.XXX.XXX.XXX - - [25/Mar/2022:12:52:18 +0100] "POST /index.php HTTP/1.1" 301 507 "-" "PHP-SOAP/8.1.3"
    
    Any ideas?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Check the error.log for details.
     
    pyte likes this.
  3. pyte

    pyte Well-Known Member HowtoForge Supporter

    The apache error.log show no errors related. Last error was this morning around 6. :/
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    It might be that the PHP on your server is unable to verify the SSL certificate, you can add options to the soap call to disable SSL cert verification.
     
    pyte likes this.
  5. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    That shouldn't return a 301 redirect code, though I don't know what would cause that offhand (web server misconfiguration or ?). See if you can display the raw http response and it might give an indication.
     
    pyte likes this.
  6. pyte

    pyte Well-Known Member HowtoForge Supporter

    I've implementet it like this:


    PHP:
    $context stream_context_create([
        
    'ssl' => [
            
    // set some SSL/TLS specific options
            
    'verify_peer' => false,
            
    'verify_peer_name' => false,
            
    'allow_self_signed' => true
        
    ]
        ]);
        
        
    $client = new SoapClient(null, array('location' => $soap_location,
                                             
    'uri'      => $soap_uri,
                                             
    'stream_context' => $context));
    But no luck either
     
  7. pyte

    pyte Well-Known Member HowtoForge Supporter

    Can you elaborate further? Should i just wget the https://hosting.xxxx.com/remote?
     
  8. pyte

    pyte Well-Known Member HowtoForge Supporter

    I've rewrote the script like this:

    PHP:
    function create_soap_session() {
        
    // login data for the soap interface
        
    $username 'userXXXXX';
        
    $password 'passXXXXXX';
        
    $soap_location 'https://hosting.xxx.com/index.php';
        
    $soap_uri 'https://hosting.xxx.com/remote/';

        
    // configure soap client
        
    $GLOBALS['client'] = new SoapClient(null,
                            array(
                               
    'location' => $soap_location,
                              
    'uri'      => $soap_uri,
                              
    'stream_context' => stream_context_create(array('ssl'=> array('verify_peer'=>false,'verify_peer_name'=>false)))));
        try {
            
    // Login to the remote server
                
    if($GLOBALS['session_id'] = $GLOBALS['client']->login($username,$password)) {
                    echo 
    'Session ID: '.$GLOBALS['session_id']."\n";
            }
        } catch (
    SoapFault $e) {
            die(
    'ERROR: SOAP Error: '.$e->getMessage());
        }
    }
    The error message still appears, but i don't see anything in access.log or error.log. Any ideas?
     
  9. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    pyte likes this.
  10. pyte

    pyte Well-Known Member HowtoForge Supporter

    The code looks like this:

    PHP:
    <?php

        $username 
    'USER';
        
    $password 'PASS';
        
    $soap_location 'https://hosting.xxx.com/index.php';
        
    $soap_uri 'https://hosting.xxx.com/remote/';

        
    $GLOBALS['soapClient'] = new SoapClient(null,
                            array(
                               
    'location' => $soap_location,
                              
    'uri'      => $soap_uri,
                              
    'stream_context' => stream_context_create(array('ssl'=> array('verify_peer'=>false,'verify_peer_name'=>false)))));
        echo 
    htmlentities($soapClient->__getFunctions());
       
        try {
            
    $results $soapClient->login($username$password);
        }
        catch (
    SoapFault $soapFault) {
            
    var_dump($soapFault);
            echo 
    "Request :<br>"htmlentities($soapClient->__getLastRequest()), "<br>";
            echo 
    "Response :<br>"htmlentities($soapClient->__getLastResponse()), "<br>";
        }
    ?>
    This is the result:

    Code:
    object(SoapFault)#2 (14) {
      ["message":protected]=>
      string(33) "looks like we got no XML document"
      ["string":"Exception":private]=>
      string(0) ""
      ["code":protected]=>
      int(0)
      ["file":protected]=>
      string(44) "/mnt/c/Users/pyte/Desktop/test.php"
      ["line":protected]=>
      int(16)
      ["trace":"Exception":private]=>
      array(1) {
        [0]=>
        array(5) {
          ["file"]=>
          string(44) "/mnt/c/Users/pyte/Desktop/test.php"
          ["line"]=>
          int(16)
          ["function"]=>
          string(6) "__call"
          ["class"]=>
          string(10) "SoapClient"
          ["type"]=>
          string(2) "->"
        }
      }
      ["previous":"Exception":private]=>
      NULL
      ["faultstring"]=>
      string(33) "looks like we got no XML document"
      ["faultcode"]=>
      string(6) "Client"
      ["faultcodens"]=>
      string(41) "http://schemas.xmlsoap.org/soap/envelope/"
      ["faultactor"]=>
      NULL
      ["detail"]=>
      NULL
      ["_name"]=>
      NULL
      ["headerfault"]=>
      NULL
    }

    Seems like something is going wrong here. As i dont't see a connection on the server at all. Does it even communicate with the server?
     
  11. pyte

    pyte Well-Known Member HowtoForge Supporter

    Well i've tried it even simpler:
    PHP:
    <?php
        $client 
    = new SoapClient('https://hosting.xxx.com/remote');
        
    $response $client->GetPosts($request_data);
        return 
    $response;
    ?>
    Which returns

    Code:
    Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://hosting.xxx.com/remote' : Document is empty
     
  12. pyte

    pyte Well-Known Member HowtoForge Supporter

    Oh my god... It is so stupid i am ashamed lol


    Code:
        $soap_location = 'https://hosting.xxx.com/remote/index.php';
        $soap_uri = 'https://hosting.xxx.com/remote/';
    The "remote" part of the $soap_location URL was missing...

    :mad:
     
    Jesse Norell likes this.
  13. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    Good catch. Likely the 301 redirect was the base index.php redirecting to the login page.
     

Share This Page