使用curl执行链接

时间:2014-08-01 19:42:56

标签: php curl hyperlink

我正在尝试使用curl执行链接(没有重定向页面)。 见下面我的代码...

$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;

但是我得到了错误请求的回复。
当我尝试将网址更改为www.google.com时,它似乎正在执行。当我在浏览器中手动使用此链接时,它按预期执行 - 向我发送消息。让我知道是否有更好的方法来执行链接而不重定向页面...

1 个答案:

答案 0 :(得分:-1)

这可能是一个非常古老的问题。但是,当你说到SMSGatewayHub + SO时,它已经没有得到答案并在谷歌中弹出,我将继续提出替代方案。

获取课程https://github.com/adarshdec23/SMSGatewayhub。它适用于促销和交易短信。

以下是使用它的step by step guide。 它使用API​​密钥而不是您的用户名和密码。完成后,该类会进行API调用(不带cURL)。它很简单,可以完成工作。