简体   繁体   中英

Equivalent of curl's "resolve" option in HTML/Javascript page

I have an ingress controller that, in order to access certain resources behind it, I need to specify the resource via curl 's --resolve feature. For example, this request will fail (ie not access the endpoint I need):

curl http://foo/endpoint

However, this request will succeed:

curl --resolve foo:80:192.168.100.123  http://foo:80/endpoint

In short, I require the equivalent of the --resolve feature, but in a simple HTML page instead. The end goal is to just be able to achieve this --resolve functionality via a web browser. I've tried various graphical tools such as "RESTer" and other REST client plugins for Firefox, but none of them seem to support this functionality. So, I guess my only remaining option is to write a web page (ie HTML) that can accomplish the same thing.

Question: how do I craft/issue such a request so I can execute it in a browser, rather than via curl ? Is this just some HTTP header hackery that I need to implement? I know that trying to do something like setting the Host field in the HTTP header doesn't work, so I assume it's more complicated than that.

Edit: it seems the curl -specific name for the feature is CURLOPT_RESOLVE .

There is no equivalent feature in fetch or XHR .

Hostname resolution cannot be overridden. You can't even make a request directly to an IP address and override the Host request header because it is marked as a forbidden header .


The closest you could come would be to write a proxy (using server-side code) and then make the request from the browser to the proxy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM