html - 为什么http请求从客户端发送到服务器两次(OPTION和POST)

标签 html http post angular http-options-method

当我单击提交按钮时,http 请求从客户端发送到服务器两次。 第一个是 OPTIONS,另一个是 POST 方法。

登录表单 enter image description here

HTTP 请求 enter image description here

最佳答案

根据Mozilla Developer Network :

Preflighted requests

Unlike simple requests (discussed above), "preflighted" requests first send an HTTP OPTIONS request header to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a request is preflighted if:

It uses methods other than GET or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted. It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)

关于html - 为什么http请求从客户端发送到服务器两次(OPTION和POST),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39034178/

相关文章:

java - 从线程外部更新进度对话框

python - 使用 POST 和 urllib2 访问 Web API

html - 使用 JQuery Ajax 提交特定表单

api - 我应该向没有足够访问权限的 REST API 用户返回 401 或 405 响应代码吗?

html - 如何在页面加载时将 HTML 中的初始值获取到 Angularjs 中的 Controller

python - HTTP 错误 415 我做错了什么?

python - 如何使用Python请求登录网站?

PHP 发帖

javascript - 如何刷新历史记录的页面。状态更改(单击后退按钮时)?

html - 无法正确对齐容器类中的文本?