2017-02-16 140 views
0

我有这个问题。我需要将我的bulksms网关提供给我的api链接粘贴到我正在构建的站点中。链接是smsplus4.routesms.com。如果使用www或http://www前缀访问此链接,则此链接不起作用。现在我有卷曲功能如何使用cURL而不使用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前缀的情况下让卷曲为我工作? 在此先感谢。

+2

你试过http://smsplus4.routesms.com吗? – mith

+0

你从http://stackoverflow.com/questions/13867430/curl-a-domain-without-http-www得到你的答案。 –

+0

是的,我做了,没有工作 – david

回答

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"> 
相关问题