I'm trying to set up Windows 8.1 virtual machine through VirtualBox for testing a server running on my Mac (running Yosemite 10.10.3). VirtualBox sets up a the IP 10.0.2.2 to point to the host machine's localhost (where the server is running). To connect to a remote server with fairly specific CORS constraints, I need to point the guest OS's localhost to that address. I've tried adding an entry to the `C:\Windows\System32\Drivers\etc\hosts file, but while it works for other strings (like 'test' and 'foo') it doesn't work for localhost. I've run across a couple threads (https://serverfault.com/questions/4689/windows-7-localhost-name-resolution-is-handled-within-dns-itself-why) that obliquely refer to this functionality being moved into the DNS resolver, but not how to change it beyond saying that it's in group policy somewhere. Can anyone tell me how to set the localhost of the Windows 8.1 VM to a custom address?
1 Answer
CORS relies on the following headers:
Request:
- Origin
Response
- Access-Control-Allow-Origin
- Access-Control-Allow-Credentials
Add your subdomain to the Origin
Request header, e.g. foo.bar.com Add the Access-Control-Allow-Origin Response
header with your localhost
value, e.g. localhost:9999
. Add the Access-Control-Allow-Credentials Response
header with a value of true
.
References
-
Thanks for resurrecting this old thread, but the whole point was that I had no control of the CORS headers. Commented Oct 17, 2018 at 15:56
-
@AdamMcCormick I didn't realize that. In my case, I was working on Citrix and could not modify the hosts file as noted above. I also could not modify the
Access-Control-Allow-Origin
request header on the server. I realized that I could modify theOrigin
request header and theAccess-Control-Allow-Origin
response header via a chrome extension Commented Oct 17, 2018 at 19:52
127.0.0.1
/::1
or there is some place I need to check for whether it has been changed. ftr I don't believe it's a good idea to changelocalhost
, because many applications expect to be able to use it interchangeably with 127.0.0.1, e.g. some server application might bind explicitly to the IP address but its client app will use the name.