简体   繁体   中英

How to make API request with PHP cURL by passing JSON multidimensonial array?

I'm trying to wrap my head around this. I have a multidimensional JSON array. I need to make an API request with PHP cURL. I did find curl_setopt_array in the manual but I still need help. How do I achieve this?

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);

Try this:

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

Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM