首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想将post方法表单转换为curl命令

我想将post方法表单转换为curl命令
EN

Stack Overflow用户
提问于 2019-11-06 15:01:35
回答 2查看 379关注 0票数 1

我在做一个auto SMS system。但是短信提供商给了我post方法表单,但我想由我自己用curl命令修改它。

他们给我提供了

代码语言:javascript
复制
<head>
<title>SMS</title>
</head>

<body>

    <form name="sms" method="post" > 
        <input type="text"  placeholder="send to number" name="to" /><br />
        <input type="textarea"  placeholder="sms" name="msg" /><br />
        <input type="submit" value=" OK " />
    </form>

    <?php     
     $apikey='$2y$10$t..Yr.YDG0kXYiuLwQ78OecDgz6/qh.1xSWx77mXjczkk3AEKvTZe';

     if (isset($_POST["msg"]) ) {
         $sendto = $_POST["to"];
         $fullNumber = '880' . substr(preg_replace('/\D/', '', $sendto), -10);
         $msg = urlencode($_POST["msg"]);
         // $masking='CITY PORTER';
         // $masking=urlencode($masking);
         // masking $url='http://example.com/smsapi/masking?api_key='.$apikey.'&smsType=text&maskingID='.$masking.'&mobileNo='.$fullNumber.'&smsContent='.$msg.'';

         $url='http://example.com/smsapi/non-masking?api_key='.$apikey.'&smsType=text&mobileNo='.$fullNumber.'&smsContent='.$msg.'';

         if ( !empty($_POST["to"])  && !empty($_POST["msg"])) {
             $curl = curl_init();

             curl_setopt_array($curl, array(
                 CURLOPT_RETURNTRANSFER => 1,
                 CURLOPT_URL =>$url,
                 CURLOPT_USERAGENT =>'My Browser'
             ));

             $resp = curl_exec($curl);
             echo $resp;
             curl_close($curl);

         } 

         else

        { echo "Field is empty";}

     }

   ?>
</body>

我将它转换为curl命令,但这仍然不起作用。我只想输入多个值,而不是set() 1值。

代码语言:javascript
复制
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row[mailing_no]; 
$message = "Dear Guardian, ". $row[name] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$response = curl_exec($ch);
curl_close ($ch);
EN

回答 2

Stack Overflow用户

发布于 2019-11-06 16:01:26

试试看,我希望你的问题能解决

代码语言:javascript
复制
<div id="send_reply"></div>
<form name="sms" method="post" > 
    <input type="text"  placeholder="send to number" name="to" id="phone" /><br />
    <input type="textarea"  placeholder="sms" name="msg" id="mess" /><br />
    <input type="submit" value=" OK " id="send_btn" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#send_btn").click(function(){
            var txt1=$("#phone").val();
            var txt2=$("#mess").val();
            $.ajax({
                url : 'check.php',
                method : 'GET',
                data : {txt1:txt1,txt2:txt2},
                success:function(dda){
                    $("#send_reply").html(dda);
                }
            });
        });

    });
</script>
票数 3
EN

Stack Overflow用户

发布于 2019-11-06 16:06:19

我想我们遗漏了$row键的双引号,试试这个:

代码语言:javascript
复制
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row["mailing_no"]; 
$message = "Dear Guardian, ". $row["name"] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$response = curl_exec($ch);
curl_close ($ch);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58724690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档