您可以使用 fetch API 设置主机 header
Can you set the Host header using fetch API
我有一个反向代理服务器,它会根据主机 header 将您重定向到不同的服务。
但是,当使用浏览器向该服务器发出请求时,Host
始终设置为 URL 中的域名。我试过了:
fetch("http://foo.com", {"headers":{"Host":"bar.foo.com"}})
但是不行
Host
是 forbidden header names:
之一
A forbidden header name is an HTTP header name that cannot be modified programmatically.
不行。您不能设置禁止通过浏览器发出请求Headers。
您可以在此处获取禁止列表 headers - https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
这里有类似的答案:
Ajax request: Refused to set unsafe header
Not able to set HTTP Host header on $.ajax request
我有一个反向代理服务器,它会根据主机 header 将您重定向到不同的服务。
但是,当使用浏览器向该服务器发出请求时,Host
始终设置为 URL 中的域名。我试过了:
fetch("http://foo.com", {"headers":{"Host":"bar.foo.com"}})
但是不行
Host
是 forbidden header names:
A forbidden header name is an HTTP header name that cannot be modified programmatically.
不行。您不能设置禁止通过浏览器发出请求Headers。
您可以在此处获取禁止列表 headers - https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
这里有类似的答案:
Ajax request: Refused to set unsafe header
Not able to set HTTP Host header on $.ajax request