响应头

来自 FourA API 的每个 response 都包含一组自定义 headers。它们对于追踪、支持和事后分析非常有用。

FourA 设置的 Headers

Header 设置于 描述
X-Foura-Request-Id 每个 /api/* response,包括错误和 401 标识此 request 的 UUID。请在您的客户端记录它。
Content-Type 每个 response 外层 envelope 始终为 application/json。目标网站的 content-type 会在 envelope 的 headers 字段中返回。

X-Foura-Request-Id

每次对 POST /api/single/POST /api/proxy/POST /api/browser/ 的调用都会标记一个 UUID。即使身份验证失败,该 header 也会被设置,因此您也可以关联配置错误的调用。

curl -i -X POST https://eu.api.foura.ai/api/single/ \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"method": "GET", "url": "https://example.com"}'
HTTP/1.1 200 OK
X-Foura-Request-Id: 9f1c4e6c-7b2a-4d3e-8a1f-2c9d8e4a3b15
Content-Type: application/json
...

何时使用

  • 支持工单:提供该 request ID,我们就可以在记录中找到确切的调用。
  • 您自己的日志:将其与您的应用程序日志行一起存储。如果客户投诉“数据在 14:32 出现错误”,您可以重放确切的 request。
  • Dashboard 追踪:相同的 ID 会出现在您管理的 key 的 Activity feed 中,因此您可以打开匹配的行并检查捕获的 request 和 response。

示例:在您的客户端记录日志

import logging
import requests

log = logging.getLogger(__name__)

def fetch(url, api_key):
    resp = requests.post(
        "https://eu.api.foura.ai/api/single/",
        headers={"X-API-Key": api_key, "Content-Type": "application/json"},
        json={"method": "GET", "url": url},
    )
    request_id = resp.headers.get("X-Foura-Request-Id", "no-id")
    log.info("foura request_id=%s url=%s status=%s", request_id, url, resp.status_code)
    resp.raise_for_status()
    return resp.json()
async function fetchPage(url, apiKey) {
  const resp = await fetch('https://eu.api.foura.ai/api/single/', {
    method: 'POST',
    headers: { 'X-API-Key': apiKey, 'Content-Type': 'application/json' },
    body: JSON.stringify({ method: 'GET', url })
  });

  const requestId = resp.headers.get('X-Foura-Request-Id') || 'no-id';
  console.log(`foura request_id=${requestId} url=${url} status=${resp.status}`);

  return resp.json();
}

缓存行为

API 不会在 responses 上设置 Cache-ControlETag。每次调用都会请求后端。如果您需要缓存,请在您的客户端添加。

目标 Response Headers

目标网站返回的 headers 不在 FourA API response 中。它们作为 headers 字段在 JSON envelope 内部返回。对于 Single 和 Proxy endpoints,这是一个包含每跳 header 对象的数组(每个重定向步骤对应一个条目)。对于 Browser endpoint,它是最终 response headers 的扁平对象。

{
  "status": 200,
  "headers": [
    { "Content-Type": "text/html; charset=utf-8", "Server": "..." }
  ],
  "data": "<!doctype html>...",
  "total_time": 0.42
}

如果您需要特定的目标 header,请从 envelope 的 headers 字段中读取,而不是从 API 调用本身的 HTTP response 中读取。

相关内容

更新于: 2026年6月30日