将表单动作包装成curl php

时间:2015-12-18 15:13:28

标签: php curl

我是php开发的新手,我刚刚听说过curl。我有这个数据,我在表格行动中发布

<form id="new_member_sms" name="new_member_sms" method="post" action="http://myserver.com/app_api.php?view=send_sms&amp;&amp;user=username&amp;&amp;pass=password&amp;&amp;message=hello+this+message+is+dynamic+from+server&amp;&amp;sender_id=BlaySoft&amp;&amp;to=<?php echo $row_rs_sms['phone_no']; ?>&amp;&amp;key=4">

</form>

我想知道我是否可以将此帖子消息"http://myserver.com/app_api.php?view=send_sms&amp;&amp;user=username&amp;&amp;pass=password&amp;&amp;message=hello+this+message+is+dynamic+from+server&amp;&amp;sender_id=BlaySoft&amp;&amp;to=<?php echo $row_rs_sms['phone_no']; ?>&amp;&amp;key=4"包装在php curl中并将其发送到服务器

2 个答案:

答案 0 :(得分:2)

您案例中PHP的curl帖子的基本版本如下:

$data = array(
    'view' => 'send_sms',
    'user' => 'username',

    // ...
    // add remaining post fields here
    // ...
);

$url = 'http://myserver.com/app_api.php';

$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_exec($handle);

$data数组应包含您要通过POST

发送的所有参数

答案 1 :(得分:0)

如果您想提交表单(不使用curl),请在表单中包含所有参数作为隐藏输入:

<form id="new_member_sms" name="new_member_sms" method="post" action="http://myserver.com/app_api.php">

  <input type="hidden" name="view" value="send_sms">
  <input type="hidden" name="user" value="username">

  <!-- and so on - put all your parameters here -->

  <input type="submit" value="Submit">
</form>