繁体   English   中英

SoapServer()调用无法访问wsdl文件

[英]SoapServer() call not able to access wsdl file

我有一个基于symfony的产品,我必须在其中公开Soap API。 我创建了wsdl文件,在输入用户名和密码后可以从浏览器访问以进行基本的http身份验证。

当我使用SoapClient调用该API并通过头提供用户名和密码时,它能够访问WSDL并调用SoapServer Endpoint。 但是当SoapServer()调用该wsdl链接时,它显示错误。

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;

我也有一个.htaccess:

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>

所以这里控件转到SoapServer()调用,但是在尝试访问SoapServer()中的wsdl时它显示: -

错误{“500”:“错误:SOAP-ERROR:解析WSDL:无法从' http://example.com/soaptest?wsdl '加载:无法加载外部实体” http://example.com/soaptest ?wsdl “”}

那么有没有办法在SoapServer调用中提供Basic Auth用户名和密码? 因为我认为SoapServer在查找WSDl文件时无法访问该链接。 此外,所有文件都在同一台服务器上。 并且没有外部呼叫

我也试过SoapUI并发生了同样的错误。

.htaccess中的最后3行有助于解决这个问题,但有没有更好的方法来解决这个问题?

.htaccess是我的项目所必需的,因此无法删除。

您确定SoapServer能够将URL用作WSDL文件吗? 它应该是本地文件,而不是远程文件。 如果它工作,可能是因为PHP可以加载URL ressource,就像它们使用fopen包装器在本地机器上一样。 请参阅此处的示例: http//php.net/manual/en/soapserver.soapserver.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM