如何使用邮递员向此脚本发送请求

时间:2020-06-17 07:40:20

标签: php json postman

我有这个脚本,我需要使用邮递员发送请求。但是我不知道如何在此脚本中实现它,文档在这里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);

1 个答案:

答案 0 :(得分:0)

我为您逐步构建了一个示例,请注意关键词quoted

对官方api文档的示例引用

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

关于Sample request data


1。创建一个新标签页

2。将Url设置为API https://sms.bongolive.africa/api/v1/send

URL

3。将Method更改为POST

Method

4。将Authorization设置为Basic Auth

绿色块是{{}}中的变量,表示您的api_keysecret_key

Authorization

5。 HeaderContent-Type设置为application-json

(如果更改了BODY的原始类型,则可能会更改) 而且您可以看到authorization的标题也在这里

Header

6。添加Body原始数据

JSON格式

Body