简体   繁体   English

相当于 HTML/Javascript 页面中 curl 的“解析”选项

[英]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.我有一个入口控制器,为了访问它后面的某些资源,我需要通过curl--resolve功能指定资源。 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.简而言之,我需要等效的--resolve功能,但在一个简单的 HTML 页面中。 The end goal is to just be able to achieve this --resolve functionality via a web browser.最终目标是能够通过网络浏览器实现这个--resolve功能。 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.我尝试了各种图形工具,例如“RESTer”和其他用于 Firefox 的 REST 客户端插件,但它们似乎都不支持此功能。 So, I guess my only remaining option is to write a web page (ie HTML) that can accomplish the same thing.所以,我想我唯一剩下的选择是编写一个可以完成同样事情的网页(即 HTML)。

Question: how do I craft/issue such a request so I can execute it in a browser, rather than via curl ?问题:我如何制作/发出这样的请求,以便我可以在浏览器中执行它,而不是通过curl Is this just some HTTP header hackery that I need to implement?这只是我需要实施的一些 HTTP 标头黑客吗? 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.我知道尝试执行诸如在 HTTP 标头中设置Host字段之类的操作是行不通的,因此我认为它比这更复杂。

Edit: it seems the curl -specific name for the feature is CURLOPT_RESOLVE .编辑:似乎该功能的特定于curl名称是CURLOPT_RESOLVE

There is no equivalent feature in fetch or XHR . fetchXHR没有等效的功能。

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 .您甚至无法直接向 IP 地址发出请求并覆盖Host请求标头,因为它被标记为禁止标头


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.最接近的是编写一个代理(使用服务器端代码),然后从浏览器向代理发出请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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