如何通过传递JSON多维数组,用PHP cURL发出API请求



我正在努力解决这个问题。我有一个多维JSON数组。我需要用PHP cURL做一个API请求。我确实在手册中找到了curl_setopt_array,但我仍然需要帮助。我该如何做到这一点?

阵列

$json = array(
"user" => $email,
"attributes" => array(
"name" => "Janet User",
"password" => $email_password,
"delivery_forward" => false
)
);

cURL

//
// Get cURL resource
//
$curli = curl_init();
//
// Set some options - we are passing in a useragent too here
//
curl_setopt_array($curli, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://horizon.opensrs.net:55443/X-Username:".$connection_details['reseller_username']."/X-Signature:".$connection_details['api_key']."/",
CURLOPT_USERAGENT => 'some company'
]);
//
// Send the request & save response to $resp
//
$respc = curl_exec($curli);
//header('Content-Type: application/json');
$c_response =json_decode($respc, true);
print_r($c_response);

试试这个:

curl_setopt($curli, CURLOPT_POSTFIELDS, $json);
// withContent-Type:multipart/form-data;

祝好运

最新更新