CURL - 使用GET发送变量不起作用

时间:2014-11-27 14:14:42

标签: php curl

我想将请求发送到另一个具有GET请求的站点,并且应该返回一个字符串值。我使用以下cURL代码来实现此目的,但它失败了。

    $user           =   'username';
    $password       =   'password';
    $sender_id      =   'myid';
    $sender_mobile  =   mobile number;
    $message_text   =   'Hi Testing SMS';
    $priority       =   'ndnd';
    $sms_type       =   'normal';
    $redirect_link  =   "http://bhashsms.com/api/sendmsg.php?user=$user&pass=$password&sender=$sender_id&phone=$sender_mobile&text=$message_text&priority=$priority&stype=$sms_type";

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$redirect_link);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

    $output=curl_exec($ch);

    if($output == false)
    {
        echo "Error Number:".curl_errno($ch)."<br>";
        echo "Error String:".curl_error($ch);
    }
    $info = curl_getinfo($ch);
    curl_close($ch);

但如果我使用标题成功发送,则以下是使用标题

    $user           =   'username';
    $password       =   'password';
    $sender_id      =   'myid';
    $sender_mobile  =   mobile number;
    $message_text   =   'Hi Testing SMS';
    $priority       =   'ndnd';
    $sms_type       =   'normal';
    $redirect_link  =   "http://bhashsms.com/api/sendmsg.php?user=$user&pass=$password&sender=$sender_id&phone=$sender_mobile&text=$message_text&priority=$priority&stype=$sms_type";

    header("Location:$redirect_link");

我哪里错了!!!

1 个答案:

答案 0 :(得分:1)

$sender_mobile = mobile number;上的错误应该与此$sender_mobile = 'mobile number';

相同