【问题标题】:How to set the host header in playwright如何在剧作家中设置主机头
【发布时间】:2021-10-08 13:33:46
【问题描述】:

我需要能够更改 url 的主机头。我尝试设置额外的标头,但我不断收到无效参数错误。

from playwright.sync_api import sync_playwright    

def get_title():
    with sync_playwright() as playwright:

        browser = playwright.chromium.launch(headless=True)
        context = browser.new_context(
            user_agent="testing",
        )
        context.set_extra_http_headers({"host": "example.com"})
        page = context.new_page()
        page.goto(url="http://111.222.333.444", wait_until="domcontentloaded")

        title = page.inner_html(selector="title")

        context.close()
        browser.close()

        return title

将页眉或上下文设置为相同的错误。可以用playwright设置主机头吗?

【问题讨论】:

    标签: python playwright playwright-python


    【解决方案1】:

    Chromium 不允许您覆盖 Host 标头。我想这是因为Host 是浏览器内部管理的东西。 Source.

    为什么要修改这个标头?

    【讨论】:

    • 我要测试的服务在 Web 服务器前面有一个负载均衡器,我想直接使用其 IP 定位 Web 服务器,然后将主机标头设置为我想要的网站。
    猜你喜欢
    • 1970-01-01
    • 2022-11-17
    • 2022-07-18
    • 2023-01-19
    • 1970-01-01
    • 2021-08-01
    • 2022-01-01
    • 2018-12-27
    • 1970-01-01
    相关资源
    最近更新 更多