简体   繁体   English

肥皂函数不返回php中的字符串

[英]soap function not returning string in php

I have a script which return a string in below format我有一个脚本,它以以下格式返回一个字符串

 {"showStatus":[{"large":980,"small":200,"title":"New Arrival<\/span>gothrough:   Red","status":6,"Id":87643}],"totalStatus  kers":2}1

I have curl code which get this data from other site after login.我有 curl 代码,可以在登录后从其他站点获取这些数据。 I am developing a soap server to share this detail with other servers as well instead of again login and get this data.我正在开发一个soap服务器来与其他服务器共享这个细节,而不是再次登录并获取这些数据。 but I am not getting this data on other server through soap client.但我没有通过soap客户端在其他服务器上获取这些数据。 My code for soap server is我的肥皂服务器代码是

<?php

 $server = new SoapServer(null,
                     array('uri' => "urn://mytest/result"));

 function get_data()
 {
 $cookie = 'cookie.txt';
 $url1="http://example.com/city/getdata/";
 $ch = curl_init();
 curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X     10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112   Safari/534.30');
curl_setopt ($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR,       $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE,      $cookie);
 curl_setopt($ch, CURLOPT_URL, $url1);
$result = curl_exec($ch);
return $result;
}

$server->addFunction('get_data');
$server->handle();
?>

and soap client on other server is having this code和其他服务器上的肥皂客户端有这个代码

 $client = new SoapClient(null, array(
  'location' => "http://x.x.x.x/soapserver/soapserver.php",
  'uri'      => "urn://mytest/result"));

 $result = $client->
    __soapCall("get_data");

echo $result;
?>

I am getting output of "1" instead of that string.我得到“1”而不是那个字符串的输出。 Please comment if you know any error in this如果您知道这有任何错误,请发表评论

You would need to set CURLOPT_RETURNTRANSFER to get the result on success.您需要设置CURLOPT_RETURNTRANSFER才能获得成功的结果。

Add this line before curl_execcurl_exec之前添加这一行

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_exec() returns TRUE on success or FALSE on failure. curl_exec()成功时返回 TRUE,失败时返回 FALSE。 However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.但是,如果设置了 CURLOPT_RETURNTRANSFER 选项,它将在成功时返回结果,在失败时返回 FALSE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM