2013-07-28 29 views
0

我的PHP代码(free.php)是网址编码错误?在<a href="http://techmentry.com/free.php" rel="nofollow">http://techmentry.com/free.php</a>

<?php 
{ 
//Variables to POST 
$access_token = "b34480a685e7d638d9ee3e53cXXXXX"; 
$message = "hi"; 
$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, 
      array('access_token' => $access_token, 
       'message' => urlencode('hi'), 
       'send_to' => $send_to,) 
     ); 

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

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

我收到此错误:该消息是空白的

这个错误的意思是:“消息栏是空白的或不正确的URL编码“(正如我的短信网关所说)。但正如你所看到的,我的信息栏不是空白的。

回答

0

我相信你无法发送阵列CURLOPT_POSTFIELDS,你就需要用下面的

curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=".$accesstoken."&message=".urlencode('hi')."&send_to=".$send_to); 

我希望这能解决它

0

使用http_build_query()来代替行:

<?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"; 
} 
?> 
相关问题