【发布时间】:2020-03-04 17:31:11
【问题描述】:
这是我的表单(html):
<div class="body">
<form method="post" action="index.php">
<div id="form">
<div class="formInput">
<label>To:
<input type="text" name="to" id="to" />
</label>
</div>
<div class="formInput">
<label>From:
<input type="text" name="from" id="from" />
</label>
</div>
<div class="formInput">
<label>Message:
<input type="text" name="message" id="message" />
</label>
</div>
<div class="formInput">
<label>Email:
<input type="text" name="email" id="email" />
</label>
<div class="formInput">
<label>Api_Secret:
<input type="text" name="api_secret" id="api_secret" />
</label>
</div>
</div>
<input type="submit" value="Submit" />
</div>
</form>
这是我使用 curl 处理 http 请求的 php:
to 通常是一个数字
from 是数字或字符串
消息既有数字又有字符串
email 只是普通的 email@email.com
api_secret 包括数字和字符串。
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://domainname.com/dashboard/api',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'to' => $_POST['to'],
'from' => $_POST['from'],
'message' => $_POST['message'],
'email' => $_POST['email'],
'api_secret' => $_POST['api_secret'],
],
]);
$response = curl_exec($ch);
curl_close($ch);
echo($response);
?>
正确的申请表应该是这样的:
https://domainname.com/dashboard/api?to={PHONE NUMBER}&from={SENDER ID}&message={TEXT}&email{YOUREMAIL}&api_secret={API SECRET}
但似乎没有从表单中取出并发送...我尝试使用 PostBin 查询和正文似乎都是空的。 我不知道该做什么或如何从这里开始。 非常感谢任何帮助。
更新: 更改了 php,使其正确发布数据:
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://domainname.com/dashboard/api',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'to' => $_POST['to'],
'from' => $_POST['from'],
'message' => $_POST['message'],
'email' => $_POST['email'],
'api_secret' => $_POST['api_secret'],
],
]);
$response = curl_exec($ch);
curl_close($ch);
echo($response);
?>
而不是查询看起来像:
123&text&text2&email@email.com&123abc
看起来像这样:
123:text:text2:email@email.com:123abc:
【问题讨论】:
-
首先 var_dump($_POST) 以确保您正在接收数据。
标签: php html curl post php-curl