Jump to content

davyb

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Posts posted by davyb

  1. Hi there,

    I am working with a webservice which allows me to send it a username and password and it will return an an object which includes two strings. One is just an "Ok" and the other is a cookie (like 1%2C%2C%2C2087364217%2C2087310473%....... etc)

     

    I can login ok and set extract the cookie... I then use the soapclient __setCookie to set the cookie for all further calls to the Webservice. However when I make the next call I am getting an error saying that the call is unauthorised as if I have not logged in or the cookie has not been passed....

     

    Please help!! Im at a loose end and I dont know what else I can do...

     

    Here is the code

     

    <?php
    // Caching 
    ini_set("soap.wsdl_cache_enabled", "0");
    
    // WSDL locatie
    $url = "some.wsdl";
    
    // Nieuwe SoapClient klasse
    $soap = new SoapClient($url, array('trace' => true));
    
    // Try loggin into the webservice and retrieving a token - this part works fine!!
    for($i = 0; $i < 3; $i++){
    
    try{
    
    	$result = $soap->opLogin(array('name' => 'Usename', 'cleartext' => 'password'));
    
    	// token is in the result 
    	$token = $result->info;
    
    	// Trim the result to get only the cookie
    	$token = trim(str_replace("PubAuth1=", "", $token));
    
    	// Print token
    	echo "token - cookie:";
    	print($token);
    	echo "<br>";
    
    	// Set cookie
    
    	$soap->__setCookie('PubAuth1', $token);
    
    	// Now make a call to the webservice to set a new user.... THIS PART DOES NOT WORK!!!
    	for($i = 0; $i < 3; $i++){
    		try{
    
    			$result2 = $soap->__soapCall("opSetUser", array('email' => 'david@bustedmedia.com', 'p' =>'password123'));
    			//$result2 = $soap->opSetUser(array('email' => 'david@bustedmedia.com', 'p' => 'lalala'));
    
    			// Print result
    			echo "opSetUser result: ";
    			var_dump($result2);
    			exit;
    		}
    		catch(Exception $ex){
    			echo "opSetUser error: " . $ex->getMessage() . "<br>";
    
    		}
    	}
    
    }
    catch(Exception $ex) {
    	echo "opLogin error: " . $ex->getMessage() . "<br>";
    }
    
    }
    ?>

  2. Apologies,

    this is my code (few typos in the last one...) :P

     

    <?php
    
    function createSession() {
            global $soap;
    
            $responseHeader = $soap->__getLastResponseHeaders();
    
    var_dump($responseHeader);
    
            $sessionPos=strpos($responseHeader, "PubAuth1=");
    
            if ($sessionPos === false) {
                echo "No session id was found. Exiting.\n";
                exit();
            }
            //cookie will always be 32 bytes
            $cookie = substr($responseHeader,$sessionPos + 11,32);
    
            #
            # Set the Cookie name for the next request
            $soap->__setCookie("PubAuth1", $cookie);
        }
    
    
    ini_set("soap.wsdl_cache_enabled", "0");
    
    $url = "some.wsdl";
    
    
    $soap = new SoapClient($url, array('trace' => true));
    
    for($i = 0; $i < 3; $i++){
    
    try{
    
    	$result = $soap->opLogin(array('name' => 'Username', 'cleartext' => 'password'));
    
    
    	$token = $result->info;
    
    	$token = trim(str_replace("PubAuth1=", "", $token));
    
    
    	// Set cookie
    	createSession();
    
    	// Retry loopje
    	for($i = 0; $i < 3; $i++){
    		try{
    
    			$result2 = $soap->__soapCall("opSetUser", array("email" => "me@me.com", 'p' =>'password123'));
    
    
    		}
    		catch(Exception $ex){
    			echo "opSetUser error: " . $ex->getMessage() . "<br>";
    
    		}
    	}
    
    }
    catch(Exception $ex) {
    	echo "opLogin error: " . $ex->getMessage() . "<br>";
    }
    
    }
    ?>

  3. Hi guys,

    Im trying to work with a wsdl which allows me to login and sends back a token (cookie) in the response. Whenever I strip out the token and the use __setCookie to set the cookie for future requests all other requests will not authenticate... Anyone any ideas please? Im really at a loose end...

     

    Heres the code Im using...

     

    <?php
    
    ini_set("soap.wsdl_cache_enabled", "0");
    
    $url = "some.wsdl";
    //$url = "http://ws.some.com/services/some?wsdl";
    
    $soap = new SoapClient($url, array('trace' => true));
    
    
    // try 3 times to login
    for($i = 0; $i < 3; $i++){
    
    try{
    
    	$result = $soap->opLogin(array('name' => 'username', 'cleartext' => 'password'));
    
    	$token = $result->info;
    
    	$token = trim(str_replace("PubAuth1=", "", $token));
    
    	// Print token
    	echo "token - cookie:";
    	print($token);
    	echo "<br>";
    
    	// Set cookie
    	//$soap->__setCookie('PubAuth1', $token);
    	createSession();
    
    	// Retry loopje
    	for($i = 0; $i < 3; $i++){
    		try{
    
    			// This is the second call which will not authenticate....
    			$result2 = $soap->__soapCall("opSetUser", array("email" => "me@you.com", 'p' =>'password123'));
    
    			// Print result
    
    			echo "opSetUser result: ";
    			var_dump($result2);
    			exit;
    		}
    		catch(Exception $ex){
    			echo "opSetUser error: " . $ex->getMessage() . "<br>";
    		}
    	}
    
    }
    catch(Exception $ex) {
    	echo "opLogin error: " . $ex->getMessage() . "<br>";
    }
    
    }
    ?>

     

    THanks in advance.

     

    Davy

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.