带有-d命令的卷曲请求

问题描述 投票:0回答:1

[我想用-d执行curl命令以使用Africa Talking API发送短信,但是我无法从服务器获得任何响应,而是在响应正文中有false,请帮助我如何将请求发送到新的卷曲。

这里是https://build.at-labs.io/docs/sms%2Fsending的卷曲样本>

curl -X POST \
    https://api.sandbox.africastalking.com/version1/messaging \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -H 'apiKey: MyAppApiKey' \
    -d 'username=MyAppUsername&to=%2B254711XXXYYY,%2B254733YYYZZZ&message=Hello%20World!&from=myShortCode'

据我所知,下面是我实施的内容

$messages = array(
    'username'=>'sandbox', //rather my username
    'to'=>$phone, // 266XXXXXXX,266XXXXXX
    'message'=>$text,//Hello
    'from'=>$from //Sandbox
);

$url = "https://api.sandbox.africastalking.com/version1/messaging";
//$url="https://api.africastalking.com/version1/messaging";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type:application/x-www-form-urlencoded',
    'apiKey:my-api-key'
));

curl_setopt($ch, CURLOPT_POSTFIELDS, ($messages)); //json_encode($messages)

$server_output = curl_exec($ch);
curl_close($ch);

var_dump($server_output);

输出false

我想用-d执行curl命令以使用Africa Talking API发送短信,很遗憾,我无法从服务器获得任何响应,而是在响应正文中有错误的信息,请帮我发送... ...

php curl libcurl
1个回答
0
投票
Curl还可以。...我认为问题出在AfricasTalking文档上。但是,这为我工作。
© www.soinside.com 2019 - 2024. All rights reserved.