为什么POST请求不总是预检?

编程入门 行业动态 更新时间:2024-10-27 00:30:16
本文介绍了为什么POST请求不总是预检?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

根据 MDN ,POST请求不是如果Content-Type是 application/x-www-form-urlencoded , multipart/form-data 或 text/plain 中的任何一个,则进行预检.

According to MDN, POST requests are not preflighted if the Content-Type is any of application/x-www-form-urlencoded, multipart/form-data, or text/plain.

但是 multipart/form-data 并不完全像 application/xml 一样不安全吗?例如,无论端点接受哪种内容类型,我都希望始终禁止对URL bank/money-orders/的跨域POST请求.

But isn't multipart/form-data exactly as unsafe as application/xml? For instance I would expect cross-origin POST requests to the url bank/money-orders/ to always be disallowed, regardless of the content type the endpoint accepts.

推荐答案

由于:在甚至没有想到CORS之前,就有可能仅通过例如从一个来源发送的网页发送跨域POST请求.用户将结果填写到另一个来源的页面上,然后单击 Submit 按钮将其发送到另一个来源.

Because: Before CORS was ever even conceived of, it was possible to send a cross-origin POST request just by, e.g., a Web page from one origin sending to another origin the results from a user filling out a form on page at one origin and clicking a Submit button to send it to another origin.

因此,从根本上说,CORS不会改变这种行为-它不会阻止或禁止这种行为,因为在CORS出现之前已经可以并且允许这样做.

So, basically, CORS doesn’t change that behavior—it doesn’t prevent it or disallow it, because it was already possible and allowed before CORS came along.

但是,当时还没有办法在这样的POST请求中发送自定义标头.但是CORS可以做到这一点-提出服务器以前从未见过或必须处理的新请求.因此,预检的目的是要基本上对服务器说,这是一种新的POST(或GET)类型,您必须表明自己选择加入并单击(或使用新方法).

Back then though, there was no way to send custom headers in such a POST request. But CORS makes it possible to do that—to make a new kind of request that servers hadn’t previously seen or had to deal with. So, the purpose of the preflight is to basically say to the server, here’s this new type of POST (or GET) that you must indicate you’re opting-in for and OK with (or new method).

但是,如果POST请求与基本上已经在Web上允许的简单POST请求的类型没有任何不同,则不必直接前往服务器.

But that heads-up to the server is not necessary if the POST request is not any different from the kind of simple POST requests that have basically always been allowed on the Web already.

更多推荐

为什么POST请求不总是预检?

本文发布于:2023-10-09 16:44:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476236.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!