首页 > 解决方案 > 如何通过传递 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
)
);

卷曲

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

标签: phpjsoncurl

解决方案


尝试这个:

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

祝你好运


推荐阅读