php - PHP Curl 请求运行两次
问题描述
不明白出了什么问题。该代码是直接来自服务提供商的代码片段,但它似乎仍然运行了两次。
// Define recipients
$recipients = ['##########'];
$url = "https://gatewayapi.com/rest/mtsms";
$api_token = "******";
$json = [
'sender' => 'Sende name',
'message' => 'message here',
'recipients' => [],
];
foreach ($recipients as $msisdn) {
$json['recipients'][] = ['msisdn' => $msisdn];
}
// time: 1587715200
print_r($json);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch,CURLOPT_USERPWD, $api_token.":");
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($json));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
print($result);
$json = json_decode($result);
print_r($json->ids);
解决方案
推荐阅读
- razor - RazorPageTemplate 从子部分设置值?
- mysql - 如何将一个表中的列与另一个表中的多个列配对?
- android - 将视频聊天声音重定向到蓝牙 android
- python - 为什么 python 中的 sqlite3 模块只在一个目录中创建所有数据库?
- groovy - 无法从 groovy 脚本创建带注释的 git 标签
- sql - 在以下 CASE WHEN 语句中使用 SELECT AS 别名 - Spark SQL
- react-final-form - 如何防止将重复值添加到 react-final-form-array 中?
- r - 根据行和列元数据将 data.frame 中的一个值除以备用 data.frame 中的另一个值
- c# - C# Winform 使用 Interop 与 microsoft Outlook 365 应用程序客户端
- python - 如何在 Dash 应用程序的新行上打印