php调用web services两种方法soap和curl

http://www.webxml.com.cn/zh_cn/index.aspx

一、使用soap调用

<?php
 //服务器支持soap扩展:
  /*Example 1:
  $client = new SoapClient("http://fy.webxml.com.cn/webservices/EnglishChinese.asmx?wsdl");
  $parameters = array("wordKey"=>"test");
  //中英文双向翻译返回数据:数组
  $result = $client->TranslatorString($parameters);
   echo "<pre>";
  print_r($result->TranslatorStringResult)."<br />";
   echo "</pre>";
//中英文双向翻译返回数组含句子例子:
  $result1 = $client->Translator($parameters);
  echo "<pre>";
  print_r($result1->TranslatorResult)."<br />";
  echo "</pre>";
//获得候选词:
  $result2 = $client->SuggestWord($parameters);
  echo "<pre>";
  print_r($result2->SuggestWordResult)."<br />";
  echo "</pre>";
//获得朗读MP3字节流,返回数据:字节数组 Byte[]
  $result3 = $client->GetMp3($parameters);
  echo "<pre>";
  print_r($result3)."<br />";
  echo "</pre>";
  */


 /*Example2:

  $client = new SoapClient("http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl");
  $param = array('theIpAddress'=>'202.96.134.33');
  $result = $client->getCountryCityByIp($param);
  echo "<pre>";
  print_r($result->getCountryCityByIpResult);
  echo "</pre>";
 
  $result1 = $client->getGeoIPContext($param);
  echo "<pre>";
  print_r($result1);
  echo "</pre>";
 
  $result2 = $client->getVersionTime(
  );
  echo "<pre>";
  print_r($result2);
  echo "</pre>";

  */
  //Example3:

  $client = new SoapClient("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl");
  //获得国内手机号码归属地省份、地区和手机卡类型信息
  $parm=array('mobileCode'=>'1367007','userID'=>'');
  $result=$client->getMobileCodeInfo($parm);
  echo ($result->getMobileCodeInfoResult)."<br>";
  //获得国内手机号码归属地数据库信息
  $result1 = $client->getDatabaseInfo($parm);
  print_r($result1)."<br>";
 
// 获取SOAP类型列表(Returns list of SOAP types )
    echo '<pre>';
    print_r($client->__getTypes ()) ;
    echo '</pre>';
 
// 获取webservice提供的函数
    echo '<pre>';
    print_r($client->__getFunctions ()) ;
    echo '</pre>';    
//服务器不支持soap扩展的情况下,可引入网上开源的类库   
?>

二、使用curl中POST

<?php
     cPost('l8200352367');
     /**
         * 使用CURL中POST方式提交数据
         *@param string $xml 要提交的$xml数据
         */ 
     function cPost($phone){
            $curlPost = "mobileCode=$phone&userID=";
            $ch = curl_init();//初始化curl会话,返回一个句柄
            curl_setopt($ch, CURLOPT_URL, "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo");
            curl_setopt($ch, CURLOPT_POST, 1);//启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样
            curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);//将 curl_exec() 获取的信息以文件流的形式返回,而不是直接输出
            $res = curl_exec($ch);
            curl_close($ch);
            var_dump($res);
         }



 


转载于:https://my.oschina.net/u/214052/blog/395832

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值