Var*_*run 5 php soap wsdl web-services symfony
我有一个基于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")
),
)),
));
Run Code Online (Sandbox Code Playgroud)
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;
Run Code Online (Sandbox Code Playgroud)
我也有一个.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>
Run Code Online (Sandbox Code Playgroud)
所以这里控件转到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是我的项目所必需的,因此无法删除.
Jay*_*ore -1
您确定 SoapServer 能够使用 URL 作为 WSDL 文件吗?它应该是本地文件,而不是远程文件。如果它有效,可能是因为 PHP 可以使用 fopen 包装器加载 URL 资源,就像它们在本地计算机上一样。请参阅此处的示例: http: //php.net/manual/en/soapserver.soapserver.php
| 归档时间: |
|
| 查看次数: |
457 次 |
| 最近记录: |