How to make http request in nodejs to url which is not linked to DNS but registered in hosts file?

StackOverflow https://stackoverflow.com/questions/16294436

Question

I am working on remote sandbox with ip 190.34.24.56 (not real ip, just for example)

Hosts file contains this string:

190.34.24.56 web.sandbox.com

I have access to url web.sandbox.com from browser, but when try to send http request I get an error: ENOTFOUND (domain name not found).

How to send http request from nodejs to url which not have dns record? (I can't enter to sandbox using 190.34.24.56, because there is host-server works which determine incoming url and redirects request to other port, so I can use only web.sandbox.com)

Was it helpful?

Solution

I haven't actually tried this, but you could try passing in the domain header along with your request:

Host: yourhostname.com

See full list of HTTP headers: List of HTTP header fields

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top