【发布时间】:2020-07-08 12:05:30
【问题描述】:
请有人帮助我
我正在尝试使用file_get_contents 向POST 发送请求,但我收到了 415 代码错误消息。我不是专业开发人员,我想知道我的源代码有什么问题。这是我的问题:
- 我生成了一个令牌,它是第二个请求的参数
- 生成的令牌必须用于 POST 请求
我收到 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);
【问题讨论】:
-
415 不支持的媒体类型 (RFC 7231)
-
你得到$token了吗?
-
Content-length, Content-type 都缺少请求头
-
是的@VishalSolanki 我得到了$token,但我不知道我是否正确使用它。我必须如何更改内容类型和内容长度?
-
检查我的答案
标签: php post token file-get-contents