【发布时间】:2020-03-02 23:11:13
【问题描述】:
为了发出 HTTP 请求,有人建议我尝试使用 PHP,并给了我一段代码来处理:
$url = 'https://example.com/dashboard/api';
$data = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
所以我获取了代码,编辑了我需要的字段,将其粘贴到 .php 文件中,上传到我的 Web 服务器(运行 PHP 5.6),然后在尝试运行 .php 文件时,我得到了HTTP 错误 500。
我完全是新手,我什至不确定我是否正确地做所有事情。
【问题讨论】:
-
检查您的 PHP 错误日志以了解 500 错误的原因。
-
你应该学会使用
curl,它更容易使用,更灵活。 -
RFC2606 合规性、格式化、消除噪音