1.用file_get_contents()函数
1 $params = array('key' => '8d284859d04cfeeea6b0771f754adb49', 2 'location' => $_COOKIE["lng"].",".$_COOKIE["lat"]); 3 4 $url3 = "http://restapi.amap.com/v3/geocode/regeo"; 5 6 if (strripos('?', $url3)) { 7 $url4 = $url3 . http_build_query($params); 8 } else { 9 $url4 = $url3 . '?' . http_build_query($params); 10 } 11 12 $ret2 = json_decode(file_get_contents($url4)); 13 14 var_dump($ret);
2.用php的curl拓展
1 $url2 = 'http://www.sojson.com/open/api/weather/json.shtml'; 2 3 $params = array('city' => '长沙'); 4 5 if (strripos('?', $url2)) { 6 $url = $url2 . http_build_query($params); 7 } else { 8 $url = $url2 . '?' . http_build_query($params); 9 } 10 11 $data = 'city=长沙'; 12 $curlobj = curl_init(); 13 curl_setopt($curlobj, CURLOPT_URL, $url); 14 curl_setopt($curlobj, CURLOPT_HEADER, 0); 15 curl_exec($curlobj);