douchibu7040 2014-10-08 18:06
浏览 199
已采纳

只需在cURL中通过GET发布变量

so I'm trying to make a small API here. I'll be only sending some information via header (get params) and I'm not using any POST parameters. Here's the code that I've written.

function sendSMS($message, $number)
{
  /*** Connection Params **/
  /*** Build the request parameters ***/
  $service="sms_api_call_receiver.php";
  $number="1212";
  $message="asas";
  $result = sendPost("https://www.domain.com/smsapp/" . $service . "?message=".urlencode($message)."&number=".$number);
  return $result;
}//function

function sendPost($Url)
{
   // Initialisation
   $ch=curl_init();
   // Set parameters
   curl_setopt($ch, CURLOPT_URL, $Url);
   // Return a variable instead of posting it directly
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   // Active the POST method
   //curl_setopt($ch, CURLOPT_POST, 1) ;
   // Request
   //curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   // execute the connexion
   $result = curl_exec($ch);
   // Close it
   //return curl_error($ch);
   curl_close($ch);
   return $result;
}

On the receiver file, I have this code :-

if(isset($_GET['message']))
{
    return true;
}
else
{
    return "12212";
}

But when I test, the output I get is :-

string '' (length=0)

What am I doing wrong here?

Troubleshooting I tried to see if curl_error returned anything. But I could see nothing. Any suggestions here would be helpful.

  • 写回答

2条回答 默认 最新

  • dtgvl48608 2014-10-08 18:19
    关注

    Are you sure there is something wrong there? If $_GET['message'] is set (in your test example it is) the script (sms_api_call_receiver.php) returns true and stops the execution.

    Because it is HTTP request, and the response is empty, you'll get as result in the sendSMS() function string with 0 length.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?