Php 以post格式向web服务发送多维数组

Php 以post格式向web服务发送多维数组,php,web-services,Php,Web Services,我想向一个web服务发送一个请求,我想向该web服务发送的数据是一个多维数组 这是阵列: $array = array( array( 'search_product' => 'syntha-6 isolate One', 'search_product1' => 'syntha-6 isolate Two', 'search_product

我想向一个web服务发送一个请求,我想向该web服务发送的数据是一个多维数组

这是阵列:

$array = array( array(
                        'search_product' => 'syntha-6 isolate One',
                        'search_product1' => 'syntha-6 isolate Two',
                        'search_product2' => 'syntha-6 isolate Three',
                        'search_product3' => 'syntha-6 isolate Four',
                        'search_product4' => 'syntha-6 isolate Five',
                        'search_brand1' => 'bsn',
                        'search_brand2' => 'BSN'
                      ),
                array(
                        'search_product' => 'syntha-6 isolate Six',
                        'search_product1' => 'syntha-6 isolate Seven',
                        'search_product2' => 'syntha-6 isolate Eight',
                        'search_product3' => 'syntha-6 isolate Nine',
                        'search_product4' => 'syntha-6 isolate Ten',
                        'search_brand1' => 'bsn',
                        'search_brand2' => 'BSN'
                      ),
                array(
                        'search_product' => 'syntha-6 isolate H',
                        'search_product1' => 'syntha-6 isolate K',
                        'search_product2' => 'syntha-6 isolate L',
                        'search_product3' => 'syntha-6 isolate M',
                        'search_product4' => 'syntha-6 isolate N',
                        'search_brand1' => 'bsn',
                        'search_brand2' => 'BSN'
                      ),
            );      
这是我用来将数据发送到Web服务的curl代码

$send_data = array('data'=>$array);
$content   = json_encode($send_data);
$url       = "http://52.53.227.143/API_test1.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

curl_close($curl);

$response = json_decode($json_response, true);
print_r($response);
这是我在webservices服务器上使用的代码:

$post       = json_decode($_POST);
$json_array = json_encode($post);

echo $json_array;
但这对我不起作用


请建议我如何实现此功能。

以json和json http头发送数组

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

以json和json http头发送数组

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

谢谢你的回答,但我已经厌倦了这个解决方案。你用这些东西检查过结果了吗$err=curl\u errno($ch)$errmsg=curl\u错误($ch)$header=curl\u getinfo($ch)Its giving me follow错误:警告:json_decode()期望参数1为字符串,第23行/var/www/html/API_test1.php中给出的数组为null这是我的webserivce代码:$content=json_decode($\u POST,true)$json_数组=json_编码($content);echo$json_数组;有人有什么解决方案吗?你能试试
$postdata=file\u get\u contents('php://input');而不是$\u post谢谢你的回答,但我已经厌倦了这个解决方案。你用这些东西检查过结果了吗$err=curl\u errno($ch)$errmsg=curl\u错误($ch)$header=curl\u getinfo($ch)
Its giving me follow错误:警告:json_decode()期望参数1为字符串,第23行/var/www/html/API_test1.php中给出的数组为null这是我的webserivce代码:$content=json_decode($\u POST,true)$json_数组=json_编码($content);echo$json_数组;有人有什么解决方案吗?你能试试
$postdata=file\u get\u contents('php://input');而不是$\u POST