- 论坛徽章:
- 0
|
class CurlPRC_Class
{
var $ch; // curl handle
function CurlPRC_Class()
{
$this->ch = null;
$this->ch = CurlPRC_Class::create();
return true;
}
function __destruct()
{
if ($this->ch != null)
{
curl_close($this->ch);
$this->ch = null;
}
return true;
}
function create() // init handle
{
$ch = null;
if (!function_exists('curl_init'))
{
return false;
}
$ch = curl_init();
if (!is_resource($ch))
{
return false;
}
return $ch;
}
function call($url, $data) // rpc call
{
if (!is_array($data)) return false;
$post_args = json_encode($data);
// set
curl_setopt($this->ch, CURLOPT_TIMEOUT, 3);
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_HEADER, false);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_FORBID_REUSE, false);
// curl_setopt($ch, CURLOPT_PROXY, "192.168.1.1");
// curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, "post=$post_args");
// call
echo "........1B\n";
$post_ret = curl_exec($this->ch);
echo "........2B\n";
if (curl_errno($this->ch))
{
return false;
}
$call_ret = json_decode($post_ret, true);
if ($call_ret['return'] == "true")
{
return $call_ret;
}
return false;
}
}
<?php
$rpc = new CurlPRC_Class();
$update_addr = "http://192.168.0.10/rpc_update.php";
$post_data = array();
$post_data["devid"]='SO6J0K7K';
echo "........1A\n";
$ret = $rpc->call($update_addr, $post_data);
echo "........2A\n";
if ($ret == false)
{
echo "rpc call error <br>\n";
exit;
}
?>
谁帮看看哪出错了,
老出现rpc call error
但是服务器端的确收到了客户端发过来的信息,我已试验过) |
|