请有人帮助我
我正在尝试使用POST
file_get_contents
发出请求,但收到415代码错误消息。我不是专业开发人员,我想知道源代码中有什么问题。这是我的问题:
我收到415错误代码消息。我不知道如何更正该来源
$tok=file_get_contents('https://restapi.bulksmsonline.com/rest/api/v1/sms/gettoken/username/xxxx/password/xxxx');
$toke =json_decode($tok, true);
$token=$toke['token'];
$data = json_encode(
array(
'from' => 'TEST',
'to' => '335546821546',
'type'=> 'Text',
'content'=> 'Test',
'sendDateTime'=> '2020/07/07'
)
);
$options = array('http' =>
array(
'method' => 'POST',
'header' => "Authorization Token " . base64_encode("$token"),
'content' => $data
)
);
$context = stream_context_create($options);
$url = 'https://restapi.bulksmsonline.com/rest/api/v1/sms/send';
$result = file_get_contents($url,false,$context);
答案 0 :(得分:0)
如果您只是获得令牌并且仅在邮寄电话中遇到问题,那么我注意到您错过了一些请求标头:
像Content-type,Content-length,我已经检查了不同的URL,对我来说尝试尝试
<?php
$tok=file_get_contents('https://restapi.bulksmsonline.com/rest/api/v1/sms/gettoken/username/xxxx/password/xxxx');
$toke =json_decode($tok, true);
$token=$toke['token'];
$data = json_encode(
array(
'from' => 'TEST',
'to' => '335546821546',
'type'=> 'Text',
'content'=> 'Test',
'sendDateTime'=> '2020/07/07'
)
);
$options = array('http' =>
array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n" .
"Content-length: " . strlen($data) . "\r\n" .
"Authorization Token: " . base64_encode("$token") . "\r\n",
'content' => $data
)
);
$context = stream_context_create($options);
$url = 'https://restapi.bulksmsonline.com/rest/api/v1/sms/send';
$result = file_get_contents($url,false,$context);
var_dump($result);