Php URL编码错误?

Php URL编码错误?,php,api,curl,Php,Api,Curl,我的PHP代码(free.PHP)是 我收到这个错误:消息是空白的 此错误表示:“消息字段为空或未正确进行URL编码”(如我的SMS网关所述)。但是,正如您所看到的,我的消息字段不是空的。我相信您不能向CURLOPT_POSTFIELDS发送数组,您需要将该行替换为以下内容 curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=".$accesstoken."&message=".urlencode('hi')."&send_t

我的PHP代码(free.PHP)是


我收到这个错误:消息是空白的


此错误表示:“消息字段为空或未正确进行URL编码”(如我的SMS网关所述)。但是,正如您所看到的,我的消息字段不是空的。

我相信您不能向CURLOPT_POSTFIELDS发送数组,您需要将该行替换为以下内容

curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=".$accesstoken."&message=".urlencode('hi')."&send_to=".$send_to);
我希望这能解决它

使用():


curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=".$accesstoken."&message=".urlencode('hi')."&send_to=".$send_to);
<?php
{
  $postdata = array();

  //Variables to POST
  $postdata['access_token'] = "b34480a685e7d638d9ee3e53cXXXXX";
  $postdata['message']      = "hi";
  $postdata['send_to']      = "existing_contacts";

  //Initialize CURL data to send via POST to the API
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "http://freesmsgateway.com/api_send");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata) );

  //Execute CURL command and return into variable $result
  $result = curl_exec($ch);

  //Do stuff
  echo "$result";
}
?>