2017-02-16 3 views
0

この問題があります。私は私のビルドしているサイトで使用するために私のbulksmsゲートウェイによって私に与えられたAPIリンクをcURLするのにまかせます。リンクはsmsplus4.routesms.comです。接頭辞がwwwまたはhttp://wwwの接頭辞でアクセスすると、このリンクは機能しません。今、私はカールの機能が見つからないためhttp://wwwプレフィックスの動作しませんでしたhttp:// wwwプレフィックスなしでcURLを使用する方法

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

を持っています。 Pls私は何をしますか?プレフィックスhttp://wwwがなくても、cURLを私のために働かせるにはどうすればよいですか? ありがとうございます。

+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"> 
関連する問題