将 PHP 对象或数组从一个站点传递到另一个站点? [英] Pass an PHP Object or Array from one Site to another Site?
本文介绍了将 PHP 对象或数组从一个站点传递到另一个站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 PHP 中,如何将对象(实际上是一个数组)从一个站点传递到另一个站点(通过不丢失其原始对象结构和值)?
In PHP, how can I pass an Object (actually an Array) from one Site to another Site (by not losing its original Object Structure and Values)?
- 如何从主机站点传递/发送
- 不要从目标站点拉取数据
我想通过不使用 HTML
和网络表单直接从自动化脚本传递.
任何建议,请.
I want to pass directly from the automated script by NOT using HTML
and web forms.
Any suggestion, please.
推荐答案
最好的方法是使用 json_encode()
:
file_get_contents('http://www.example.com/script.php?data='.json_encode($object));
另一边:
$content = json_decode($_GET['data']);
或使用 cURL 发送
or send it using 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']);
这篇关于将 PHP 对象或数组从一个站点传递到另一个站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文