1

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

我的代码在这里:

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

回显文件获取内容($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>";
        }


    ?>
4

1 回答 1

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;
于 2013-05-08T10:35:32.633 回答