douzangdang2225 2014-10-31 08:03
浏览 106
已采纳

PHP Curl无效

I am new here and not a pro in php but need a small help. Actually I was given a code by my service prodvider to upload on my hosting. But when i uploaded that code on my hosting account it didnt work well and after contact the support I was told to use php curl code in some part to make it run. can anyone please help me with the issue.

Original Code:

<?php

$MobileNumber=substr($_REQUEST['VerifiedNumber'],-10);

$APIKey="<Your Dial2verify API Key Here>";
$SenderID="<6 ALPHABETIC CHARACTERS ONLY>";
$Message="<Your SMS Text Here>";

echo `curl -XPOST "http://host/SMS/SEND/$APIKey/$SenderID/$MobileNumber" -d "Msg=$Message"`;

?>

I don't know how to make the above code into curl code to make it work.

Thanks :)

  • 写回答

2条回答 默认 最新

  • douhuireng4407 2014-10-31 08:14
    关注

    The reason it did not work was that you where trying to call the command line version of cURL (and also doing the call wrong).

    The best way is to use the php cURL module to make this call. Verify first that it is installed by creating an info.php file with the contents

    <?php phpinfo();
    

    If cURL is present on that page you are good to go.

    Obviously I have not had the ability to test this code but something like this should work

    $msisdn   = substr($_REQUEST['VerifiedNumber'],-10);
    $apiKey   = "<Your Dial2verify API Key Here>";
    $senderId = "<6 ALPHABETIC CHARACTERS ONLY>";
    $message  = "<Your SMS Text Here>";
    
    $url = "http://host/SMS/SEND/$apiKey/$senderId/$msisdn";
    
    $ch = curl_init();
    
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('Msg' => $message));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
        $result = curl_exec($ch);
    
    curl_close($ch);
    
    echo 'Response from server:';
    print_r($result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据