【问题标题】:How to use postman to send request to this script如何使用邮递员向该脚本发送请求
【发布时间】:2020-06-17 18:38:29
【问题描述】:

我有这个脚本,我需要使用邮递员来发送请求。但我不知道如何在这个脚本中实现它,文档在这里https://bongolive.co.tz/api/docs 但我没有从中得到清晰的描述,因为我是初学者

<?php
//.... replace <api_key> and <secrete_key> with the valid keys obtained from the platform, under profile>authentication information
$api_key='<api_key>';
$secret_key = '<secret_key>';
// The data to send to the API
$postData = array(
    'source_addr' => 'INFO',
    'encoding'=>0,
    'schedule_time' => '',
    'message' => 'Hello World',
    'recipients' => [array('recipient_id' => '1','dest_addr'=>'255700000001'),array('recipient_id' => '2','dest_addr'=>'255700000011')]
);
//.... Api url
$Url ='https://sms.bongolive.africa/api/v1/send';

// Setup cURL
$ch = curl_init($Url);
error_reporting(E_ALL);
ini_set('display_errors', 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array(
        'Authorization:Basic ' . base64_encode("$api_key:$secret_key"),
        'Content-Type: application/json'
    ),
    CURLOPT_POSTFIELDS => json_encode($postData)
));

// Send the request
$response = curl_exec($ch);

// Check for errors
if($response === FALSE){
        echo $response;

    die(curl_error($ch));
}
var_dump($response);

【问题讨论】:

标签: php json postman


【解决方案1】:

我一步一步为你建立一个例子,注意关键词是quoted

官方api文档示例参考

https://bongolive.co.tz/api/docs/

关于Sample request data


1。创建一个新标签

2。设置 api Urlhttps://sms.bongolive.africa/api/v1/send

3。将Method 更改为POST

4。将Authorization 设置为Basic Auth

绿色块是{{}} 中的变量,请参阅您的api_keysecret_key

5。 HeaderContent-Type 设置为 application-json

(如果 BODY 的原始类型改变,它可能会改变) 你可以看到你的authorization的标题也在这里

6。添加Body原始数据

JSON 格式

【讨论】:

    猜你喜欢
    • 2018-10-16
    • 2021-07-13
    • 1970-01-01
    • 2021-11-07
    • 2020-12-11
    • 1970-01-01
    • 2016-04-03
    • 2016-10-31
    • 1970-01-01
    相关资源
    最近更新 更多