2017-02-16 141 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"> 
相關問題