微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP-肥皂错误致命错误:未捕获的SoapFault异常:[HTTP]无法连接到主机

使用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

直接将文件移动到/ var / www /下时,脚本可以正常工作:

http://localhost/soap-client.PHP

但是当我将其移动到名为PHPwebservice的子文件夹时,会出现错误.子文件夹是否像这样无关紧要:

http://localhost/PHPwebservice/soap-client.PHP

或者,如果我为此制作了VirtualHost:

http://PHPwebservice/soap-client.PHP

soap-client.PHP内容

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

soap-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:

   <?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>

谢谢.

解决方法:

如果您处于开发环境中,最好在PHP.ini中设置soap.wsdl_cache_enabled = 0.否则,在对WSDL文件(通常位于soap.wsdl_cache_dir定义的目录中)进行任何更改之后,您必须手动删除WSDL缓存.

您可能还会参考:SoapFault exception: Could not connect to host

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐