SoapServer () call cannot access wsdl file

I have a symfony based product in which I have to open the Soap API. I created a wsdl file accessible from the browser after entering Username and Pasword for basic HTTP authentication.

When I use SoapClient to call this API and provide the username and password through the header, it can access the WSDL and make a call to the SoapServer endpoint. But when SoapServer () calls this wsdl link, it shows an error.

SoapClient ():

$client = new \SoapClient('http://example.com/soaptest?wsdl', array(
        "exceptions" => 0,
        "trace" => 1,
        'stream_context' => stream_context_create(array(
            'http' => array(
                'header' => "Authorization: Basic " . base64_encode("$username:$password")
            ),
        )),
    ));

SoapServer ():

ini_set("soap.wsdl_cache_enabled", "0");

$server = new SoapServer($wsdl);    //Here SoapServer not able to access WSDl because of .htaccess

$server->setObject($this->get($class));
ob_start();
$server->handle();
$result = ob_get_clean();

return $result;

I also have .htaccess as:

DirectoryIndex app.php



<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On


    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]


    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]


    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]


    RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>

        RedirectMatch 302 ^/$ /app.php/# RedirectTemp cannot be used instead
    </IfModule>
</IfModule>
php_value date.timezone UTC

AuthType Basic
AuthName "Login"
AuthUserFile /etc/apache2/config/.htpasswd

Require expr %{REQUEST_URI} !~ m#^/(admin|login|soaptest)#
Require valid-user
#<RequireAll>
 # Require ip 127.0.0.1
#</RequireAll>

So, here the control goes to the SoapServer () call, but when trying to access wsdl in SoapServer () it shows: -

{ "500": ": SOAP-ERROR: WSDL: http://example.com/soaptest?wsdl ': " http://example.com/soaptest?wsdl ""}

, Basic Auth Username Password SoapServer?. , SoapServer WSDl . . .

SoapUI .

3 .htaccess , ?

.htaccess , .

+4

Source: https://habr.com/ru/post/1690007/


All Articles