我正在使用两个curl进行autosuggest并获取记录。当我在本地测试相同的代码时它的工作正常但是当我接受它时会获得500个内容服务器请查看此内容。
switch ($cases){
case 'city' :
$obj_biz_tmp_info= new info($db_server['CITY']);
$response_list = $obj_biz_tmp_info->getCity($string);
$obj_biz_tmp_info->close();
break;
case 'what' :
if ($_GET['search'] == "") return false;
$areasrch = $_GET['search'];
if(!empty($areasrch)){
$apiurl = 'http://192.168.1.97/auto.php?search='.urlencode(trim($areasrch)).'&city='.urlencode(trim($city)).'&stp=0&dtres=20&srch_type=2';
$ch = curl_init($apiurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "abcd");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$getResults = curl_exec($ch);
curl_close($ch);
$getResults = json_decode($getResults,true);
echo json_encode($getResults);
//print_r($getResults);
break;
}
case 'compsearch':
if ($_GET['search'] == "") return false;
$areasrch1 = $_GET['search'];
if(!empty($areasrch1)){
$apiurl = 'http://192.168.1.97/auto.php?search='.urlencode(trim($areasrch1)).'&city='.urlencode(trim($city)).'&stp=0&dtres=20&srch_type=2';
$ch = curl_init($apiurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "abcd");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$getResults1 = curl_exec($ch);
curl_close($ch);
$getResults1 = json_decode($getResults1,true);
echo json_encode($getResults1);
//print_r($getResults1);
break;
}
答案 0 :(得分:0)
http://192.168.1.97
是本地网络上的地址,可能无法从您的服务器访问。
如果auto.php
脚本托管在同一台服务器上,您可以更改此内容:
$apiurl = 'http://192.168.1.97/auto.php?search=' // rest of line ommited
到
$apiurl = 'http://' . $_SERVER['HTTP_HOST'] . '/auto.php?search=' // rest of line ommited