'YOUR_VALUE'];
$url .= '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('请求失败: ' . curl_error($ch));
}
curl_close($ch);
// 解析 JSON 响应
$data = json_decode($response, true);
echo "code: " . ($data['code'] ?? 'N/A') . "\n";
echo "msg: " . ($data['msg'] ?? $response);
?>
import requests
# 调用 API
url = "https://taoziwei.com/API/ip.php"
params = {
'ip': 'YOUR_VALUE',
}
try:
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
data = response.json()
print(f"code: {data.get('code')}")
print(f"msg: {data.get('msg')}")
except requests.exceptions.RequestException as e:
print(f"请求失败: {e}")
// 使用原生 fetch(浏览器/现代 Node.js)
const url = new URL('https://taoziwei.com/API/ip.php');
const params = {
'ip': 'YOUR_VALUE',
};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
fetch(url, { method: 'GET' })
.then(async response => {
const data = await response.json();
console.log('code:', data.code);
console.log('msg: ', data.msg);
})
.catch(error => console.error('请求失败:', error));
// Node.js (需要先安装: npm install axios)
const axios = require('axios');
const url = 'https://taoziwei.com/API/ip.php';
const params = {
'ip': 'YOUR_VALUE',};
axios.get(url, { params, timeout: 10000 })
.then(response => {
console.log('code:', response.data.code);
console.log('msg: ', response.data.msg);
})
.catch(error => {
if (error.response) {
console.error('服务器返回错误:', error.response.status);
} else {
console.error('请求失败:', error.message);
}
});
# 使用 cURL 命令行调用 API
curl -X GET "https://taoziwei.com/API/ip.php" \
--data-urlencode "ip=YOUR_VALUE" \
--connect-timeout 10 \
--max-time 30 \
-H "Accept: application/json"
# 带 API Key 鉴权(如需):
# curl -X GET "https://taoziwei.com/API/ip.php?apikey=YOUR_API_KEY"
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class ApiClient {
public static void main(String[] args) throws Exception {
StringBuilder urlBuilder = new StringBuilder("https://taoziwei.com/API/ip.php?");
urlBuilder.append("ip=YOUR_VALUE&");
String url = urlBuilder.toString();
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(10000);
conn.setRequestProperty("Accept", "application/json");
try (BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = br.readLine()) != null) response.append(line);
System.out.println(response);
} finally {
conn.disconnect();
}
}
}
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"time"
)
func main() {
// 构造 URL 与参数
base, _ := url.Parse("https://taoziwei.com/API/ip.php")
q := base.Query()
q.Set("ip", "YOUR_VALUE")
base.RawQuery = q.Encode()
// 发送请求
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get(base.String())
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}