2013-05-08 42 views
1

我試圖通過在本地運行php腳本通過遠程服務器連接web服務。我正在閱讀整個文件,它不顯示任何內容。當我在瀏覽器中嘗試使用此URL時,它會提取數據。我將權限改爲755,並啓用了allow_url_fopen,php_openssl.dll。任何建議,將不勝感激無法通過遠程連接到web服務使用php腳本

我的代碼在這裏:

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

echo file_get_contents($ url);


爲想不出連接到主機時,我試着打肥皂在遠程服務器上,我得到一個錯誤。有什麼建議麼?

代碼在這裏:

<?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>"; 
     } 


    ?> 

回答

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; 
+0

感謝響應。我會嘗試一下並回復你。 – Nikisha 2013-05-08 13:23:15

+0

我試過上面的代碼,它不接受我在遠程服務器上的ERP應用程序的URL,但與其他網站很好地工作。在我的服務器應用程序中是否有任何錯誤@ Daniel Chernenkov – Nikisha 2013-05-10 14:21:57

+0

@ user2345099您在自己的服務器上運行此代碼,因此您需要使用本地地址。它可以是'127.0.0.1'或'localhost' – 2013-05-10 15:29:01

相關問題