dongzhuo1930 2017-02-16 05:30
浏览 59

如何在没有http:// www前缀的情况下使用cURL

i have this problem. I neent to cURL an api link given to me by my bulksms gateway for use in the site i'm building. The link is smsplus4.routesms.com . This link does not work if you access it with the www or http://www prefixes. Now i have the curl function

function curl_get_contents($url)
{   
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$api = "smsplus4.routesms.com";
curl_get_contents($api);

which did not work because of the missing http://www prefix. Pls what do i do? how do i get the cURL to work for me without the http://www prefix? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doulao3905 2017-02-16 06:16
    关注

    Running exactly the code above seems to work for me.

    $ cat test.php
    <?php
    
    function curl_get_contents($url)
    {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    }
    $api = "smsplus4.routesms.com";
    echo curl_get_contents($api);  <-- Added echo to see the output
    
    ?>
    $ php test.php | head
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <!--<![endif]-->
        <!-- BEGIN HEAD -->
        <head>
            <meta charset="utf-8"/>
            <title>SmsPlus :: Login </title>
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)