就是用curl访问一个网址,得到的结果为空。但是在浏览器地址栏里直接访问,却有结果,为何?---curl模拟访问---
$url = "https://api.ispapi.net/api/call.cgi";
$curl = curl_init($url);
$postfields = "?s_entity=1234&s_login=testwangzhiwen.hexonet.net&s_pw=dirdir&command=CheckDomains&domain0=csdn.net";
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $postfields );
curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER , 1 );
$response = curl_exec($curl);
echo $response;直接在浏览器输入:
https://api.ispapi.net/api/call.cgi?s_entity=1234&s_login=testwangzhiwen.hexonet.net&s_pw=dirdir&command=CheckDomains&domain0=csdn.net却能返回信息
为什么会这样呢???
$url = "https://api.ispapi.net/api/call.cgi";
$curl = curl_init($url);
$postfields = "?s_entity=1234&s_login=testwangzhiwen.hexonet.net&s_pw=dirdir&command=CheckDomains&domain0=csdn.net";
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $postfields );
curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER , 1 );
$response = curl_exec($curl);
echo $response;直接在浏览器输入:
https://api.ispapi.net/api/call.cgi?s_entity=1234&s_login=testwangzhiwen.hexonet.net&s_pw=dirdir&command=CheckDomains&domain0=csdn.net却能返回信息
为什么会这样呢???
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; SV1)";
$header = array('Accept-Language: zh-cn','Connection: Keep-Alive','Cache-Control: no-cache'); //HEADER信息
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
//USER_AGENT
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
<?php $url = "https://api.ispapi.net/api/call.cgi";
$curl = curl_init($url);$useragent = "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; SV1)";
$header = array('Accept-Language: zh-cn','Connection: Keep-Alive','Cache-Control: no-cache'); //HEADER信息
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
//USER_AGENT
curl_setopt($curl, CURLOPT_USERAGENT, $useragent); $postfields = "?s_entity=1234&s_login=testwangzhiwen.hexonet.net&s_pw=dirdir&command=CheckDomains&domain0=csdn.net";
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $postfields );
curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER , 1 );
$response = curl_exec($curl);
echo $response;?>
试了下 貌似不行啊
其实
$url = "https://api.ispapi.net/api/call.cgi";
也可以换成的
$url = "http://api.ispapi.net/api/call.cgi";
然后Apache里面的 ssl_mod也要打开 就可以了
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$ch = curl_init($url);$useragent = "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; SV1)";
$header = array('Accept-Language: zh-cn','Connection: Keep-Alive','Cache-Control: no-cache'); //HEADER信息
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
//USER_AGENT
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , 1 );$response = curl_exec($ch);
echo $response;
返回结果
[RESPONSE]
PROPERTY[DOMAINCHECKTIME][0]=0.12
PROPERTY[DOMAINCHECK][0]=211 Domain name not available
DESCRIPTION=Command completed successfully
QUEUETIME=0
CODE=200
RUNTIME=0.124QUEUETIME=0
RUNTIME=0.192EOF