如何在不使用http:// www Prefix

时间:2017-02-16 05:30:13

标签: php http curl web

我有这个问题。我想通过我的bulksms网关向我提供api链接,以便在我所建站点中使用。链接是smsplus4.routesms.com。如果您使用www或http://www前缀访问此链接,则此链接不起作用。现在我有卷曲功能

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

由于缺少http://www前缀而无效。请问我该怎么办?如何在没有http://www前缀的情况下让cURL为我工作? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

完全按照上面的代码运行似乎对我有用。

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