简体   繁体   English

HTML 中的 HTTP 请求方法

[英]HTTP request methods in HTML

Does HTML support the direct programming of custom HTTP requests? HTML 是否支持自定义 HTTP 请求的直接编程?

For example, is there is a way to write HTML code that directly instructs the browser to make a custom GET / PUT / POST / DELETE request with custom headers, body and parameters (query string) to a particular endpoint?例如,有没有办法编写 HTML 代码,直接指示浏览器使用自定义标头、正文和参数(查询字符串)向特定端点发出自定义GET / PUT / POST / DELETE 请求?

No.不。

In general, HTML can only trigger GET requests.一般来说,HTML 只能触发 GET 请求。 The exception are forms which allow you to make POST requests as well. forms 例外,它也允许您发出 POST 请求。

You can't have a custom body (forms can encode the data in form fields using one of three encoding methods).您不能有自定义正文(表单可以使用三种编码方法之一对表单字段中的数据进行编码)。

You can't set custom headers.您不能设置自定义标题。

If by "parameters" you mean "query string", then you can type what you like in a URL (within the constraints of the URL data format).如果“参数”是指“查询字符串”,那么您可以在 URL 中输入您喜欢的内容(在 URL 数据格式的约束内)。

All those things are possible using JavaScript (via APIs like fetch and XMLHttpRequest ).使用 JavaScript (通过fetchXMLHttpRequest等 API),所有这些事情都是可能的。

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

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