夏期劇*_*期劇場 1 php xml-rpc parameter-passing json-rpc
在PHP中,如何将对象(实际上是一个数组)从一个站点传递到另一个站点(通过不丢失其原始的对象结构和值)?
我想通过NOT using HTML和web表单直接从自动脚本传递.
请提出任何建议.
最好的方法是使用json_encode():
file_get_contents('http://www.example.com/script.php?data='.json_encode($object));
另一方面:
$content = json_decode($_GET['data']);
或使用cURL发送
$url = 'http://www.example.com/script.php';
$post = 'data='.json_encode($object);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_exec($ch);
另一方面:
$content = json_decode($_POST['data']);