【发布时间】:2019-02-25 19:52:50
【问题描述】:
我是在 PHP 中使用 cURL 的新手,我想使用此 API 发送 SMS,但是当我进行所有测试时,我收到以下错误:
HTTP/1.1 400 Bad Request Content-Length: 0 X-Application-Context: application:production:8080
我查看了我的代码,但我不明白到底发生了什么:
$data=array('from' => '506712xxxx', 'to' => '50671xxxx', 'body' => 'Hola este es un mensaje de prueba' );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sms.api.sinch.com/xms/v1/xxxxx/batches");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer xxxxxx",
"Content-Type: application/json",
));
$res = curl_exec($ch);
print_r($res);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
我查看了官方文档,不知道自己做错了什么,官方文档:
https://www.sinch.com/docs/sms/http-rest.html
谢谢,我用了翻译器
【问题讨论】: