现在我正面临着为sms网关执行api的问题。他们让我打了一个网址,这是http://bulksmsgateway.in/sendmessage.php?user=........&password=.......&mobile=........&message=.......&sender=.......&type=3
但我必须在不在浏览器中加载此URL的情况下执行此操作。所以我用curl方法。我得到400错误请求错误。这是一个支持PHP的Windows服务器。
我的代码如下 -
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_USERAGENT,'Mozilla / 4.0(兼容; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_URL,$ url);
$ contents = curl_exec($ ch);
$ ee = curl_getinfo($ ch);
的print_r($ ee值);
curl_close($ CH);
if($ contents){echo'send';的print_r($内容); } else {echo'lose'; }
$ ee返回
阵 ( [url] => http://bulksmsgateway.in/sendmessage.php?user=usrname&password=pwd&mobile=9126050xxx&message=Thanking您通过FCI订购。您的订单将按时交付。您的订单号为000198。请保留以备将来参考。& sender = SUBANK& type = 3
[content_type] => text/html; charset=iso-8859-1
[http_code] => 400
[header_size] => 145
[request_size] => 411
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.094
[namelookup_time] => 0
[connect_time] => 0.047
[pretransfer_time] => 0.047
[size_upload] => 0
[size_download] => 299
[speed_download] => 3180
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.094
[redirect_time] => 0
[certinfo] => Array
(
)
[redirect_url] =>
)
我认为问题出在消息部分。 url中消息中的空格收到错误。因为没有空格的消息成功发送。 a& nbsp也没有工作。并且是forst停止(。)。请在这方面帮助我。
提前感谢。
答案 0 :(得分:2)
您应该以这种方式对 消息 查询参数进行编码:
$message = urlencode("Thanking you for ordering through FCI.Your Order will be delivered on time.Your order no is 000198.Please keep it for future");
这是 消息 参数,正确编码将作为GET参数发送:
感谢你+ +为订购+到+ FCI.Your +订单+会+是+提供+上+ time.Your +订单+不+是+ 000198.Please +保持+它+为未来
答案 1 :(得分:0)
http://www.technologyworkshops.net/tutorials-f39/curl-using-get-method-with-php-t135.html
function curlWithGetMethod($url, $data)
{
$fields_string = '';
foreach($data as $key=>$value){
$fields_string[]=$key.'='.urlencode($value).'&'; }
$urlStringData = $url.'?'.implode('&',$fields_string);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_URL, $urlStringData );
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
$data = array('first_name' => 'myname', 'email' => 'example@example.com', 'phone' => '0123456789', );
echo curlWithGetMethod(''http://www.technologyworkshops.net/', $data);
答案 2 :(得分:0)
我已经用%20替换空格,它对我来说很好。感谢大家的帮助...