【问题标题】:to execute a link using curl使用 curl 执行链接
【发布时间】:2014-08-01 19:42:55
【问题描述】:

我正在尝试使用 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 时,它似乎正在执行。当我在浏览器中手动使用此链接时,它按预期执行 - 向我发送消息。让我知道是否有更好的方法来执行链接而不重定向页面...

【问题讨论】:

  • 小心,您将userpwd 组合以及服务URL 暴露在互联网上。您确定这不是敏感数据吗?
  • 我已经在短时间内更改了它:)) 我一直渴望得到答案:(
  • 登录信息无效,如果您已经知道,很好,如果不知道,请使用正确的用户/密码尝试。另外,对您的参数进行 urlencode。
  • 任何指导请... :(

标签: php curl hyperlink


【解决方案1】:

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

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

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

【讨论】:

  • 与ops问题无关
猜你喜欢
  • 2012-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
  • 2016-06-18
  • 2012-07-11
  • 1970-01-01
相关资源
最近更新 更多