> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/web-scraper-api/features/http-context-and-job-management/headers-cookies-method.md). Agents can also search and read this documentation through its [MCP server](https://developers.oxylabs.io/~gitbook/mcp).

# 请求头、Cookie、方法

了解使用网页爬虫API 抓取时如何自定义请求头、Cookie 或 HTTP 方法。

网页爬虫API 通过使用我们团队预定义的请求头和 Cookie，最大化网站访问效率。如有需要，您也可以定义自己的请求头、Cookie 和 HTTP 方法。

## 自定义请求头

如果你需要自己的请求头，可以通过添加以下内容来使用它们 `context:force_headers` 参数并将其设置为 `true` 在提交抓取任务时。网页爬虫API会将你的自定义请求头与预定义的请求头集一起发送，然后用它们访问网站。

#### 代码示例

```json
{
    "context": [
        {
            "key": "force_headers",
            "value": true
        },
        {
            "key": "headers",
            "value": {
                "Accept-Language": "en-US,en;q=0.5"
            }
        }
    ],
    "source": "universal",
    "url": "https://example.com"
}
```

## 自定义 Cookie

如果你需要自己的 Cookie，可以通过添加 `context:force_Cookie` 参数并将其设置为 `true` 在提交抓取任务时。网页爬虫API 会将您的自定义 Cookie 与预定义的 Cookie 集一并发送，然后使用它们访问网站。如果您还想复用相同的代理 IP 地址，请查看 [代理会话](https://developers.oxylabs.io/products/cn/web-scraper-api/features/localization/proxy-location.md#sessions) 文档。

#### 代码示例

```json
{
    "context": [
        {
            "key": "force_Cookie",
            "value": true
        },
        {
            "key": "Cookie",
            "value": [
                {
                    "key": "NID",
                    "value": "1234567890"
                }
            ]
        }
    ],
    "source": "universal",
    "url": "https://example.com"
}
```

## HTTP 方法

`通用` 源使用了 `GET` 默认的 HTTP 方法。

如果你需要向目标网站提交数据，必须将 HTTP 方法设置为 `POST` 并提供一个 Base64 编码的 `POST` 请求体中的 `context:content`. 下面的示例会发送 `hello=world` (Base64: `aGVsbG89d29ybGQ=`) 到一个会回显请求的页面，这样你就可以在返回内容的 `data` 字段中看到请求体。

#### 代码示例

```json
{
    "source": "universal",
    "url": "https://httpbin.org/post",
    "context": [
        {
            "key": "http_method",
            "value": "post"
        },
        {
            "key": "content",
            "value": "aGVsbG89d29ybGQ="
        }
    ]
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/cn/web-scraper-api/features/http-context-and-job-management/headers-cookies-method.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
