以使用curl执行链接 [英] to execute a link using curl

查看:177
本文介绍了以使用curl执行链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行一个链接(没有页面被重定向)使用curl。
请参阅下面的代码...

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;

但我得到的响应为错误请求。

当我尝试将网址更改为www.google.com,似乎执行。当我手动使用这个链接在浏览器,其执行预期 - 发送消息给我。让我知道如果有更好的方式来执行一个链接,没有页面被重定向...

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...

推荐答案

这可能是一个很老题。

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.

获取类 https://github.com/adarshdec23/SMSGatewayhub =nofollow> https://github.com/adarshdec23/SMSGatewayhub 。它适用于促销和交易短信。

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

以下是分步指南使用它。
它使用一个API密钥,而不是您的用户名和密码。一旦你完成了,该类做一个API调用(没有cURL)。它很简单,完成工作。

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.

这篇关于以使用curl执行链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆