to execute a link using curl

倖福魔咒の 提交于 2019-12-13 20:40:46

问题


i am trying to execute a link (without page being redirected) using curl. see below my code...

$ch = curl_init(); // Initializing
//curl_setopt($ch, CURLOPT_URL, trim("http://api.smsgatewayhub.com/smsapi/pushsms.aspx?user=stthomasmtc&pwd=429944&to=9176411081&sid=STMTSC&msg=Dear Sam,%20choir%20practice%20will%20be%20held%20in%20our%20Church%20on%20July%2031%20at%208:00%20pm.%20Thanks,%20St.%20Thomas%20MTC!&fl=0&gwid=2")); // Set URI
curl_setopt($ch, CURLOPT_URL,"http://api.smsgatewayhub.com/smsapi/pushsms.aspx?user=stthomasmtc&pwd=429944&to=9176411081&sid=STMTSC&msg=Dear Sam,%20choir%20practice%20will%20be%20held%20in%20our%20Church%20on%20July%2031%20at%208:00%20pm.%20Thanks,%20St.%20Thomas%20MTC!&fl=0&gwid=2"); // Set URI
curl_setopt($ch, CURLOPT_HEADER, 0); //Set Header
curl_setopt($ch, CURLOPT_TIMEOUT, 300); // Time-out in seconds
$result = curl_exec($ch); // Executing
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
    $result = ""; // Executing
}
curl_close($ch); // Closing the channel
return $result;

but i get the response as Bad Request.
when i try to change the url to www.google.com, it seems executing. When i manually use this link in browser, its executed as expected - to send message to me. let me know if there is a better way to execute a link without page being redirected...


回答1:


This maybe a very old question. But since it has gone unanswered and pops up in Google when you say SMSGatewayHub + SO, I'll go ahead and present an alternative.

Get the class https://github.com/adarshdec23/SMSGatewayhub. It works with both promotional and transactional SMS messages.

Here is a step by step guide to using it. It uses an API key instead of your username and password. Once you're done with that, the class makes an API call (without cURL). Its simple and gets the job done.



来源:https://stackoverflow.com/questions/25087560/to-execute-a-link-using-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!