php - 如何通过传递 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);
解决方案
尝试这个:
curl_setopt($curli, CURLOPT_POSTFIELDS, $json);
// withContent-Type:multipart/form-data;
祝你好运
推荐阅读
- javascript - SwipeableViews 如何将 updateHeight() 作为道具传递
- google-plus - 获取“请求的身份验证范围不足。” 使用 ionic 5 和 Angular 11 从 Gmail 导入联系人时出现 403 错误代码
- cesium - 飞机 HPR 到 ECEF 方向
- rsyslog - 如果配置为转发消息,Rsyslog 将停止向 /var/log/messages 发送消息
- php - 带有 Laravel 的 YouTube Data API v3:重定向 URI 不匹配
- flutter - 如何停止在颤动中滑动(在一次滑动动画之后)
- javascript - 如何将项目添加到列表
- python-3.x - 使用 SciPy 的多变量函数局部最小值
- javascript - 从正方形列表创建矩形列表的算法?
- ip - 区块链节点如何知道何时添加了新节点?