简体   繁体   English

soap error致命错误:未捕获的SoapFault异常:[HTTP]无法连接到主机

[英]soap error Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host

I encounter this error when sending a SOAP request with the PHP SoapClient : 使用PHP SoapClient发送SOAP请求时遇到此错误:

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/phpwebservice/soap-client.php:6
Stack trace:
#0 [internal function]: SoapClient->__doRequest('__call('getCatalogEntry', Array)
#2 /var/www/phpwebservice/soap-client.php(6): SoapClient->getCatalogEntry('catalog1')
#3 {main} thrown in /var/www/phpwebservice/soap-client.php on line 6

the script works fine when moving the files directly under the /var/www/ meaning: /var/www/含义下直接移动文件时,脚本工作正常:

http://localhost/soap-client.php

but when I move it to a sub-folder called phpwebservice that error appears. 但当我将它移动到一个名为phpwebservice的子文件夹时,会出现错误。 It doesn't matter if the sub-folder is like this: 子文件夹是这样的并不重要:

http://localhost/phpwebservice/soap-client.php

or if I made a VirtualHost for it: 或者如果我为它制作了一个VirtualHost:

http://phpwebservice/soap-client.php

the content of soap-client.php : soap-client.php的内容:

    $client     = new SoapClient("catalog.wsdl");
    $catalogId      = 'catalog1';
    $response       = $client->getCatalogEntry($catalogId);
    echo $response;

soap-server.php: 皂server.php:

    function getCatalogEntry($catalogId){
    if($catalogId == 'catalog1')
            return  "<html>
                <head>
                    <title>catalog</title>
                </head
                <body>
                <p> </p>
                    <table border=1>
                    <tr>
                        <th>catalogid</th>
                        <th>journal</th>
                        <th>section</th>
                        <th>edition</th>
                        <th>title</th>
                        <th>author</th>
                    </tr>
                    <tr>
                        <td>catalog1</td>
                        <td>ibm developerworks</td>
                        <td>xml</td>
                        <td>october 2005</td>
                        <td>jaxp validation</td>
                        <td>brett mclaughlin</td>
                    </tr>
                    </table>
                </body>
            </html>";
elseif($catalogId == 'catalog2')
    return  "<html>
                <head>
                    <title>catalog</title>
                </head>
                <body>
                    <p> </p>
                    <table border=1>
                        <tr>
                            <th>catalogid</th>
                            <th>journal</th>
                            <th>section</th>
                            <th>edition</th>
                            <th>title</th>
                            <th>author</th>
                        </tr>
                        <tr>
                            <td>catalog1</td>
                            <td>ibm developerworks</td>
                            <td>xml</td>
                            <td>july 2006</td>
                            <td>the java xpath api</td>
                            <td>elliotte harold</td>
                        </tr>
                    </table>
                </body>
            </html>";
    }
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new soapserver("catalog.wsdl");
    $server->addfunction("getCatalogEntry");
    $server->handle();

catalog.wsdl: catalog.wsdl:

   <?xml version ='1.0' encoding ='UTF-8' ?>
   <definitions name='Catalog'
   targetnamespace='http://phpwebservice/catalog'
   xmlns:tns='http://phpwebservice/catalog'
   xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
   xmlns:xsd='http://www.w3.org/2001/XMLSchema'
   xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
   xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
   xmlns='http://schemas.xmlsoap.org/wsdl/'>
   <message name='getCatalogRequest'>
    <part name='catalogId' type='xsd:string'/>
   </message>
   <message name='getCatalogResponse'>
    <part name='Result' type='xsd:string'/>
   </message>
   <portType name='CatalogPortType'>
    <operation name='getCatalogEntry'>
                <input message='tns:getCatalogRequest'/>
        <output message='tns:getCatalogResponse'/>
    </operation>
   </portType>
   <binding name='CatalogBinding' type='tns:CatalogPortType'>
    <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
    <operation name='getCatalogEntry'>
    <soap:operation soapAction='urn:phpwebservice-catalog#getCatalogEntry'/>
        <input>
            <soap:body use='encoded' namespace='urn:phpwebservice-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
        </input>
        <output>
                    <soap:body use='encoded' namespace='urn:phpwebservice-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
        </output>
    </operation>
   </binding>
   <service name='CatalogService'>
    <port name='CatalogPort' binding='CatalogBinding'>
        <soap:address location='http://phpwebservice/soap-server.php'/>
   </port>
   </service>
   </definitions>

thanx. 感谢名单。

If you're in the development environment, it's better to set soap.wsdl_cache_enabled=0 in php.ini . 如果您在开发环境中,最好在php.ini设置soap.wsdl_cache_enabled=0 Otherwise you have to manually delete WSDL cache after doing any changes to WSDL file (generally located in the directory defined by soap.wsdl_cache_dir ) 否则,您必须在对WSDL文件进行任何更改后手动删除WSDL缓存(通常位于soap.wsdl_cache_dir定义的目录中)

You may also refer to: SoapFault exception: Could not connect to host 您还可以参考: SoapFault异常:无法连接到主机

I encountered this issue for a particular SOAP service when connection_timeout was not specified in my SoapClient options. 当我的SoapClient选项中未指定connection_timeout时,我遇到了特定SOAP服务的此问题。 Setting the timeout to 1 fixed the issue for me. 将超时设置为1可以解决我的问题。

$wsdl = 'https://...';
$options [
  'trace' => true,
  'exceptions' => true,
  'connection_timeout' => 1
];
$client = new SoapClient($wsdl, $options);

没关系,我只是从wsdl文件中的每一行中删除/ catalog,无论如何一切都正常。

暂无
暂无

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

相关问题 PHP的肥皂客户端,从错误的WSDL错误? “未捕获的SoapFault异常:[HTTP]无法连接到主机” - php soap client, error from bad wsdl? “Uncaught SoapFault exception: [HTTP] Could not connect to host” 致命错误:未捕获的SoapFault异常:[HTTP]发送HTTP SOAP失败 - Fatal error: Uncaught SoapFault exception: [HTTP] Failed Sending HTTP SOAP 致命错误:未捕获的SoapFault异常:[soap:Client] - Fatal error: Uncaught SoapFault exception: [soap:Client] 错误:致命错误:未捕获的SoapFault异常:[WSDL] SOAP-ERROR - Error: Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR 致命错误:未捕获的SoapFault异常:[SOAP-ENV:Client]错误找不到参数,无法连接到SoapClient - Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Error cannot find parameter and cant connect to SoapClient 致命错误:未捕获的SoapFault异常[wsdl] SOAP错误 - Fatal error: Uncaught SoapFault exception [wsdl] SOAP-ERROR 致命错误:未捕获的SoapFault异常:[HTTP]提取HTTP标头时出错 - Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers PHP SOAP:致命错误:未捕获的SoapFault异常:[HTTP]在SecurityContext中找不到身份验证对象 - PHP SOAP : Fatal error: Uncaught SoapFault exception: [HTTP] An Authentication object was not found in the SecurityContext SOAP 1.1请求致命错误未捕获到SoapFault异常:[soapenv:Server] - SOAP 1.1 Request Fatal Error Uncaught SoapFault exception: [soapenv:Server] 肥皂提供未捕获的SoapFault异常:[HTTP]访存HTTP标头时出错 - soap giving Uncaught SoapFault exception: [HTTP] Error Fetching http headers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM