[英]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.