我试图通过本地运行php脚本来连接远程服务器上的webservice。我正在读整个文件,它没有显示。当我在浏览器中尝试此URL时,它会获取数据。我将我的测试php文件的权限更改为755并启用了allow_url_fopen,php_openssl.dll。任何建议将不胜感激
我的代码在这里:
$ url ='http://mail.abc.com:10139/webservices2.0.asmx?WSDL';
echo file_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>";
}
?>
答案 0 :(得分: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;