【问题标题】:Couldn't connect to webservice over remote with php script无法使用 php 脚本通过远程连接到 web 服务
【发布时间】:2013-05-08 02:47:02
【问题描述】:

我试图通过在本地运行 php 脚本来连接远程服务器上的 web 服务。我正在阅读整个文件,它没有显示。当我在浏览器中尝试此 url 时,它会获取数据。我将权限更改为 755 的测试 php 文件并启用了 allow_url_fopen,php_openssl.dll。任何建议将不胜感激

我的代码在这里:

$url = 'http://mail.abc.com:10139/webservices2.0.asmx?WSDL';

回显文件_get_contents($url);


当我尝试通过远程服务器调用soap 时,我收到一个错误,因为无法连接到主机。有什么建议吗?

代码在这里:

    <?php


            ini_set('soap.wsdl_cache_enabled',0);
                      ini_set('soap.wsdl_cache_ttl',0);

                       $url="http://mail.abc.com:10139/webservices2.0.asmx?WSDL";

                   $client  = new  SoapClient ( null , array ( 'location'  =>  "http://mail.abc.com:10139/webservices2.0.asmx?WSDL" , 
                                             'uri'       =>  "http://mail.abc.com:10139/webservices2.0/" )) ;
   //echo file_get_contents($url); //Unable to read from url 

        $operator="xxxx";
        $operatorPassword="yyyy";
        $companyId="abc";
        $companyPassword=" ";
        $languageCode="";

        try
        {
            $response =$client->__soapCall("logon,array('Operator' => $operator, 'OperatorPassword' => $operatorPassword, 'CompanyId'=> $companyId, 'CompanyPassword' => $companyPassword, 'LanguageCode' => $languageCode));
        print_r($response);
        }
        catch (SoapFault $result) {
            echo "<pre>";
        print_r($result); 
         echo "</pre>";
        }


    ?>

【问题讨论】:

    标签: php web-services soap


    【解决方案1】:

    当我尝试访问该页面时出现错误,您确定它有效吗?

    无论如何,我建议使用此代码:

    function get_data($url) {
    
    $ch = curl_init();
      $timeout = 5;
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
      curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;
    }
    
    $variablee = get_data('http://example.com');
    echo $variablee;
    

    【讨论】:

    • 感谢您的回复。我会尝试并回复您。
    • 我尝试了上面的代码,它不接受我在远程服务器中的 ERP 应用程序的 url,但可以与其他 url 一起使用。我这边或服务器应用程序有什么问题吗@Daniel Chernenkov
    • @user2345099 您在自己的服务器上运行此代码,因此您需要使用本地地址。它可以是 '127.0.0.1' 或 'localhost'
    • 非常感谢。它对我有用。我在本地服务器中的端口有问题@Daniel Chernenkov
    • @user2345099 如果您对此答案投赞成票并将此答案标记为正确,我将不胜感激。很乐意为您提供帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-21
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 2016-05-24
    相关资源
    最近更新 更多