【发布时间】:2018-01-13 18:45:39
【问题描述】:
我正在尝试将以下 Json 发送到我的 api 站点,其中包含一条记录。 它工作正常,但我想发送多个记录,我该怎么做?
稍后我想读取一个 txt 并制作一个包含所有记录的 json。
<?php
//API URL
$url = 'http://mysitexder.net/receiveJson.php';
//create a new cURL resource
$ch = curl_init($url);
//setup request to send json via POST
$data = array(
'cod' => '321',
'name' => 'Jane',
'address' => 'Route 123456'
);
$payload = json_encode(array("user" => $data));
//attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
//set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute the POST request
$result = curl_exec($ch);
//close cURL resource
curl_close($ch);
【问题讨论】: