I use UrlFetchApp send http Header including 'Host':'www.XXX.net'
but it happen "Attribute provided with invalid value: Header:Host" error,
because i use http interceptor recopy Header of packet that connect 200 OK: HTTP
this 200 OK: HTTP Header must include 'Host':'www.XXX.net' in the send packet to the server
if exclude 'Host':'www.XXX.net' ,my request UrlFetchApp is invalid( HTTP 400 (Bad Request))
I seach some knowledge about google apps script news:
The UrlFetchApp service does not allow manual setting of the Host request header packet, but GAS will automatically generate and set the Host header based on the URL you request.
can i give up UrlFetchApp of google apps script ? can i find the other method to work around~
i test the serverless free web for example: cron-job.org and send http Header including 'Host':'www.XXX.net'
my request UrlFetchApp is invalid( HTTP 400 (Bad Request)) too . thanks~
Yes — in Google Apps Script UrlFetchApp you cannot force/set the Host header manually. Host is generated automatically from the URL by Google’s HTTP infrastructure. Trying this:
causes:
UrlFetchApp is designed to fetch external URLs through Google infrastructure and supports normal request options, headers, payload, etc., but not low-level control of protected transport headers like Host. It also requires the external request scope.
Use one of these workarounds:
If the server requires Host: www.XXX.net, then the URL itself must be:
If you need to connect to an IP address or another domain while sending Host: www.XXX.net, Apps Script cannot do that directly.
Best workaround: create a small proxy outside Apps Script, for example Cloudflare Worker, Google Cloud Run, AWS Lambda, VPS, etc. Apps Script calls the proxy, and the proxy sends the raw HTTP request with the custom Host.
Example flow:
So, no need to “give up” Apps Script entirely. Use Apps Script for scheduling/cron and data handling, but use an external proxy for the HTTP request that needs custom Host.
Also check with the server owner: many 400 Bad Request cases happen because the server expects the correct domain/SNI/TLS config, not just the Host header.