如何将多维数组发布到另一个脚本 [英] How to post multidimensional array to another script

查看:81
本文介绍了如何将多维数组发布到另一个脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我需要发送回服务器的数组,但数据很大,所以我JSON编码它导致这样的东西



I have some arrays I need to send back to the server but the data is large so I JSON encoded it resulting in something like this

{"help me":[{"href":"http:\/\/codeproject.com","key1":"20%","key2":"20%","key3":"65%}]}





哪里有大约40个阵列都有自己的href,而且每个阵列都有一百个密钥。我打算用另一个脚本识别这个有效负载,比如 $ _ POST ['help me'] (几十个数组的网关)。



我尝试了什么:



我尝试过使用guzzle(内部使用) curl)和文件获取内容,但都不能传回数据。





Where there are about 40 arrays with their own hrefs and each of these arrays have over a hundred keys. I intend to identify this payload on the other script using something like $_POST['help me'] (gateway to dozens of arrays).

What I have tried:

I've tried using guzzle (which internally uses curl) and file get contents but neither can transport the data back.

$postClient = new GuzzleClient();

	$response = $postClient->request('POST', 'http://localhost/c.php', [
	    'json' => json_decode($data, true)
	]);






and

$postClient = new GuzzleClient();

	$response = $postClient->request('POST', 'http://localhost/c.php', [
	    'body' => $data,
        'Content-Type' => 'application/json'
	]);






and also

$opts = array('http' => array('method' => 'POST', 'header'  => 'Content-Type: application/json', 'content' => json_decode($data, true)['fixtures']));


$context = stream_context_create($opts);

$result = file_get_contents('http://localhost/c.php', false, $context);



但是当我检查时使用 $ http_response_header 的响应头,我发现它是使用内容类型text / html和c.php发送的,其中包含


But when I inspect the response header using $http_response_header, I find it was sent using content type text/html and the c.php which contains

var_dump($_POST);





说数组是空的,应该有一个名为'help me'的数组。所以它似乎得到了那个脚本,但没有传输参数。但实际上,它会看到这些参数,因为当我var_dump $ _SERVER超全局而不是$ _POST时,它会向我显示选项中传递的所有参数。除请求正文或有效负载外的所有内容'QUERY_STRING'键为空,所以我尝试使用http_build_query发送URL编码的字符串,但该函数仅适用于平面数组。我甚至无法理解将这样的数组转换为查询。我也尝试了无数的在线代码片段,它们保证了数组的顺利传递但没有工作



Says the array is empty, when there should be an array there named 'help me'. So it seems to get to that script but without the transport parameters. But in reality, it sees those parameters because when I var_dump the $_SERVER superglobal instead of $_POST, it shows me all those parameters passed in the options. All except the request body or payload. The 'QUERY_STRING' key is empty so I tried sending in a URL encoded string instead using http_build_query but that function only works with flat arrays. I cannot even fathom transforming such an array into a query. I've also tried countless snippets of code online that promise the smooth delivery of the arrays but none works

推荐答案

_POST ['help me'] (通往几十个阵列的门户)。



我尝试过的事情:



我尝试过使用guzzle(内部使用curl)和文件获取内容,但都不能传回数据。



_POST['help me'] (gateway to dozens of arrays).

What I have tried:

I've tried using guzzle (which internally uses curl) and file get contents but neither can transport the data back.


postClient = new GuzzleClient();
postClient = new GuzzleClient();


response =
response =


这篇关于如何将多维数组发布到另一个脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆