API 文件
概述
301check.com 提供免費的 HTTP 重新導向鏈路 API,您可以直接整合到自己的應用程式中。無需註冊、無需 API 金鑰 — 只要發送 POST 請求即可取得結果。
✨ API 功能
- 完全免費,無需註冊
- 支援所有 HTTP 重新導向類型(301/302/303/307/308)
- 回傳完整的重新導向鏈路
- 包含回應時間、伺服器 IP 和 TLS 憑證詳情
- JSON 格式回應,易於解析
- 透過
lang參數支援雙語錯誤訊息
端點
POST
https://www.301check.com/check.php
請求格式
標頭
Content-Type: application/json
請求主體
{
"url": "https://example.com",
"lang": "en"
}
參數
url(必填)— 要檢查的網址;支援 HTTP 和 HTTPSlang(選填)— 錯誤訊息語言:en或zh。預設透過Accept-Language自動偵測。
⚠️ 網址格式
網址必須包含協定(http:// 或 https://)。如果傳入裸域名如 example.com,API 會自動加上 http://。
回應格式
成功
{
"success": true,
"timestamp": "2026-02-22T10:00:00+08:00",
"inputUrl": "https://example.com",
"finalUrl": "https://www.example.com",
"totalRedirects": 1,
"totalTime": 0.390,
"loopDetected": false,
"maxRedirectsReached": false,
"redirects": [
{
"hop": 1,
"statusCode": 301,
"statusMessage": "Moved Permanently",
"type": "permanent",
"from": "https://example.com",
"to": "https://www.example.com",
"duration": 0.234,
"ip": "93.184.216.34",
"server": "nginx/1.18.0",
"tlsInfo": {
"protocol": "TLSv1.3",
"subject": "example.com",
"issuer": "Let's Encrypt",
"expires": "2026-04-01"
},
"headers": {
"server": "nginx/1.18.0",
"location": "https://www.example.com"
}
}
]
}
錯誤
{
"success": false,
"error": "Invalid URL. Please enter a valid HTTP or HTTPS URL."
}
程式碼範例
cURL
curl -X POST https://www.301check.com/check.php \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com","lang":"en"}'
Python
import requests
resp = requests.post(
"https://www.301check.com/check.php",
json={"url": "https://example.com", "lang": "en"}
)
data = resp.json()
if data["success"]:
print(f"跳轉次數:{data['totalRedirects']},最終網址:{data['finalUrl']}")
for hop in data["redirects"]:
print(f" {hop['hop']}. {hop['statusCode']} {hop['from']}")
else:
print("錯誤:", data["error"])
JavaScript
const res = await fetch('https://www.301check.com/check.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: 'https://example.com', lang: 'en' })
});
const data = await res.json();
if (data.success) {
console.log(`${data.totalRedirects} 次跳轉 → ${data.finalUrl}`);
data.redirects.forEach(h => console.log(` ${h.hop}. ${h.statusCode} ${h.from}`));
}
PHP
<?php
$ch = curl_init('https://www.301check.com/check.php');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['url' => 'https://example.com', 'lang' => 'en']),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $data['success'] ? $data['totalRedirects'] . " 次跳轉\n" : $data['error'] . "\n";
?>
速率限制
- 每個 IP:每 10 秒 5 次請求
- 超過限制時:HTTP 429,附帶雙語錯誤訊息
錯誤處理
請務必檢查 success 欄位。可能的錯誤情況:
- 無效或缺少網址
- 超過速率限制
- 連線逾時(15 秒)
- DNS 解析失敗
- 私有/內部 IP 位址被封鎖
💡 提示
需要更高的速率限制或企業支援?請聯繫我們:api@301check.com