API 文档

目录

概述

301check.com 提供免费的 HTTP 重定向检测 API,允许你在自己的应用中集成重定向链路追踪功能。API 完全免费,无需注册或 API Key。

✨ API 特性

  • 完全免费,无需注册
  • 支持所有 HTTP 重定向类型(301/302/303/307/308)
  • 返回完整的跳转链路信息
  • 包含响应时间、服务器 IP、TLS 证书等详细数据
  • JSON 格式响应,易于解析
  • 支持语言参数(lang=zh/en)

API 端点

POST https://www.301check.com/check.php

请求格式

请求头

Content-Type: application/json

请求体

{
  "url": "https://example.com",
  "lang": "zh"
}

参数说明

⚠️ URL 格式要求

URL 必须包含协议(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",
        "cache-control": "max-age=3600"
      }
    },
    {
      "hop": 2,
      "statusCode": 200,
      "statusMessage": "OK",
      "type": "final",
      "from": "https://www.example.com",
      "to": null,
      "duration": 0.156,
      "ip": "93.184.216.34",
      "server": "nginx/1.18.0",
      "tlsInfo": { "protocol": "TLSv1.3", "issuer": "Let's Encrypt", "expires": "2026-04-01" },
      "headers": { "server": "nginx/1.18.0", "content-type": "text/html; charset=UTF-8" }
    }
  ]
}

错误响应

{
  "success": false,
  "error": "URL 格式无效,请输入有效的 HTTP 或 HTTPS 地址。"
}

代码示例

cURL

curl -X POST https://www.301check.com/check.php \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","lang":"zh"}'

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"Total hops: {data['totalRedirects']}")
    print(f"Final URL: {data['finalUrl']}")
    for hop in data["redirects"]:
        print(f"  Hop {hop['hop']}: {hop['statusCode']} {hop['from']}")
else:
    print(f"Error: {data['error']}")

JavaScript (fetch)

const resp = 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 resp.json();
if (data.success) {
  console.log('Hops:', data.totalRedirects);
  console.log('Final URL:', data.finalUrl);
}

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'],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($result['success']) {
    echo "Hops: " . $result['totalRedirects'] . "\n";
    echo "Final: " . $result['finalUrl'] . "\n";
}
?>

速率限制

为了防止滥用,API 实施以下速率限制:

错误处理

💡 提示

如果你需要更高的速率限制或企业级支持,请联系我们:api@301check.com