以下是可能导致POST请求发送两次的一些原因:
重复提交:用户可能在提交表单或发送POST请求时多次点击提交按钮或发送请求的操作,导致请求被发送多次。
页面刷新:当用户在提交POST请求后刷新页面时,某些浏览器会尝试重新发送之前的POST请求,以便用户可以重新加载页面并继续之前的操作。
跨域请求:在某些情况下,如果你的网页中存在跨域请求,浏览器可能会发送OPTIONS请求进行预检(preflight),然后再发送实际的POST请求。这样就会导致看起来像是发送了两次POST请求,但实际上第一个请求是OPTIONS请求。
重定向:如果服务器返回一个重定向响应(例如状态码为302),浏览器可能会自动跟随重定向并发送第二个POST请求。
缓存问题:一些缓存机制可能会导致POST请求被重复发送。例如,浏览器或代理服务器可能会缓存POST请求的响应,然后在后续请求时重用缓存的响应,从而导致看起来像是发送了两次POST请求。
以下是一些常见的解决方法:
根据具体的情况,你可能需要进一步调查并采取适当的解决措施来处理重复发送的POST请求。
同源策略(Same-Origin Policy)是一种浏览器安全机制,用于限制在浏览器中加载的网页脚本与来自不同源(即不同的域、协议或端口)的资源之间的交互操作。它是为了保护用户的隐私和安全而设计的。
同源策略的基本原则是,当一个网页脚本尝试访问另一个源的资源时,浏览器会阻止这种跨源的操作,以防止恶意网站利用跨域请求获取用户的敏感信息或对其他网站进行攻击。
同源策略的限制主要包括以下几个方面:
域名:同源策略要求两个网页具有相同的域名(协议、主机和端口),即使两个域名只是在协议、主机或端口上稍有不同,也会被视为不同源。例如,http://example.com 和 https://example.com 被视为不同源。
Cookie、LocalStorage 和 IndexDB:同源策略限制了对跨源的 Cookie、LocalStorage 和 IndexDB 的访问。这意味着网页脚本只能访问属于同一源的 Cookie 和存储数据,而无法读取或修改其他源的数据。
DOM 访问:同源策略限制了对跨源文档对象模型(DOM)的访问。网页脚本只能修改属于同一源的 DOM 元素,无法直接访问或修改其他源的 DOM。
XMLHttpRequest 和 Fetch 请求:同源策略对跨源的 XMLHttpRequest 和 Fetch 请求进行限制。通常情况下,这些请求只能向同源发起,无法直接访问其他源的数据。
为了允许跨域请求,浏览器引入了一些机制,如跨域资源共享(CORS)和服务器代理。这些机制允许服务器通过设置适当的响应头来授权特定的跨域请求。
同源策略在保护用户隐私和安全方面起着重要的作用,防止恶意网站滥用用户的信息。然而,有时候需要进行跨域操作,因此开发人员需要了解和遵守跨域规则,并使用适当的跨域解决方案。
预请求(Preflight Request)是在进行跨域资源共享(CORS)时,某些特定情况下由浏览器自动发送的一种HTTP请求。它是一个OPTIONS请求,用于在实际的跨域请求之前进行预检,以确定是否允许实际请求的发送。
在以下情况下,浏览器会发送预请求:
跨域请求:当浏览器发起跨域请求时,即请求的目标与当前页面的域名、协议或端口不一致时,浏览器会发送预请求。
自定义请求头:如果在跨域请求中使用了特定的自定义请求头(例如Content-Type
、Authorization
等),并且这些请求头属于 "CORS安全列表" 之外的请求头,浏览器也会发送预请求。
预请求的目的是为了确保服务器支持跨域请求并允许浏览器发送实际的跨域请求。预请求的发送和处理过程如下:
发送预请求:浏览器在发送实际的跨域请求之前,先发送一个OPTIONS请求,其中包含了一些额外的头部信息,如Origin
(指示请求的源)和Access-Control-Request-Method
(指示实际请求的方法)等。
服务器处理预请求:服务器接收到预请求后,进行预检查。它会检查请求的源是否在允许的跨域列表中,以及是否允许实际请求的方法、请求头等。
响应预请求:服务器根据预检查的结果,返回包含了对应的响应头信息的响应。响应头中重要的字段是Access-Control-Allow-Origin
(指示允许的源)和Access-Control-Allow-Methods
(指示允许的方法)等。
浏览器处理预请求响应:浏览器接收到预请求的响应后,会检查响应头中的相关字段,以确定是否允许发送实际的跨域请求。
发送实际请求:如果预请求的响应表明服务器允许实际请求,浏览器会发送实际的跨域请求,其中包含了实际的请求方法、请求头等。
需要注意的是,预请求是由浏览器自动发送的,并且在实际请求之前进行。它的目的是为了提供一种机制,确保服务器允许跨域请求,以增加安全性。服务器需要正确地处理预请求并返回适当的响应头,以允许或拒绝实际的跨域请求。
预请求就是浏览器在进行跨域请求访问时向目标浏览器发送的一个预检测请求,检测目标服务器是否支持跨域请求,预请求是一个OPTIONS请求,其中包含了一些额外的头部信息,如Origin(请求源)、Access-Control-Request-Method(实际请求的方法)和Access-Control-Request-Headers(实际请求的头部信息)。服务器收到预请求后,可以检查这些头部信息,并决定是否允许实际的跨域请求。
服务器在收到预请求后,可以通过设置响应头部中的Access-Control-Allow-Origin、Access-Control-Allow-Methods和Access-Control-Allow-Headers等字段来指定允许的跨域请求来源、方法和头部信息。如果服务器确认允许跨域请求,浏览器会继续发送实际的跨域请求,否则将阻止实际请求的发送,并返回相应的错误。
预请求机制的目的是确保服务器允许跨域请求,并在发送实际请求之前进行验证,从而保护用户的隐私和安全。开发人员需要在服务器上正确地配置CORS头部信息,以便处理预请求,并允许必要的跨域请求。
1.通过自定义中间件
package main import ( "github.com/gin-gonic/gin" ) func main() { // 创建 Gin 引擎 router := gin.Default() // 添加跨域请求的中间件 router.Use(corsMiddleware()) // 添加你的路由处理逻辑 // 启动服务器 router.Run(":8080") } // 跨域请求中间件 func corsMiddleware() gin.HandlerFunc { return func(c *gin.Context) { // 设置允许的请求来源 c.Writer.Header().Set("Access-Control-Allow-Origin", "http://example.com") // 设置允许的请求方法 c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE") // 设置允许的请求头部信息 c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") // 设置是否允许发送凭据 c.Writer.Header().Set("Access-Control-Allow-Credentials", "true") // 如果是预请求(OPTIONS请求),则直接返回 if c.Request.Method == "OPTIONS" { c.AbortWithStatus(204) return } // 继续处理实际的请求 c.Next() } }
2.官方推荐跨域请求中间件,具体可以看官方示例代码
Podman: A tool for managing OCI containers and pods
中文翻译
Podman 是一个工具,用于管理符合 OCI 标准的容器以及容器组(pods)。
Podman (the POD MANager) is a tool for managing containers and images, volumes mounted into those containers, and pods made from groups of containers. Podman runs containers on Linux, but can also be used on Mac and Windows systems using a Podman-managed virtual machine. Podman is based on libpod, a library for container lifecycle management that is also contained in this repository. The libpod library provides APIs for managing containers, pods, container images, and volumes.
中文翻译
Podman(POD 管理器)是一个用于管理容器和镜像、挂载到这些容器中的卷,以及由一组容器组成的 pods 的工具。Podman 在 Linux 上运行容器,但也可以在 Mac 和 Windows 系统上使用 Podman 管理的虚拟机。Podman 基于 libpod,这是一个用于容器生命周期管理的库,也包含在这个代码库中。libpod 库提供了用于管理容器、pods、容器镜像和卷的 API。
All releases are GPG signed. Public keys of members of the team approved to make releases are located here.
中文翻译
所有的发布都经过了 GPG 签名。已获批准进行发布的团队成员的公钥位于此处。
How talented do you have to be to get an interview with Google?
中文翻译
"要获得与谷歌的面试,需要有多大的天赋?"
I’ve helped many people get into Google and other top tier tech companies. Especially software engineers in the entire spectrum of 0 to 40 years experience. Let me tell you with confidence that you don’t have to be as naturally talented as you’re thinking. As long as you are a sincere worker, who can focus on solving problems, that’s all they are looking for.
中文翻译
"我已经帮助了许多人进入谷歌和其他顶级科技公司,尤其是软件工程师,无论是有0年经验还是有40年经验的。让我自信地告诉你,你不必像你想象的那样天赋出众。只要你是一个真诚的工作者,能够专注于解决问题,这就是他们寻找的一切。"
Why? First of all, there is no good way to measure talent. In popular culture, we measure it with IQ. But there is also a large body of research which says that IQ is not correlated with success. Here is a relevant link for your reference. But, even if you don’t believe this research; how do you decipher talent by looking at someone’s resume? Resumes are usually not very well written and often don’t tell the truth either.
中文翻译
"为什么?首先,没有一种好的方法来衡量天赋。在流行文化中,我们用智商来衡量它。但也有大量的研究表明智商与成功没有相关性。以下是一个相关链接供您参考。但即使您不相信这项研究,您如何通过查看某人的简历来解读他们的天赋呢?简历通常写得不太好,而且经常也不诚实。"
The second reason Google doesn’t insist on only interviewing talented people, is because they hire massively on scale. i.e., thousands a month, world over. If they insist on interviewing only people with talent, they won’t ever be able to hire and push great products out fast.
中文翻译
"Google不坚持只面试有才能的人的第二个原因是因为他们大规模招聘,即每个月在全球招聘成千上万人。如果他们坚持只面试有才能的人,他们将永远无法快速招聘并推出优秀的产品。"
Third reason: Google does need people with high IQ but not every position per se needs high IQ. People who are diligent and have the right approach are also critical to any big company’s success. In fact, that is how large companies are built. There are maybe 10% of positions which may need innate talent to be successfully producing right output, but the other 90% just requires sincerity and dedication to solving tough problems. Talent is massively overrated in such positions.
中文翻译
"第三个原因是:谷歌确实需要智商高的人,但并不是每个职位都需要高智商。勤奋和正确的方法对于任何大公司的成功也至关重要。实际上,这就是大公司是如何建立的。也许有10%的职位可能需要天生的才能才能成功产生正确的输出,但其他90%只需要真诚和专注于解决困难问题。在这些职位中,才能被严重高估了。"
Finally and most fundamentally, they have great faith in their own interview process. The interview process is rigorous and only selects the best prepared candidates. Interview preparation for Google is a great proxy for your sincerity and dedication to solving tough problems.
The only time they have to use a loose proxy for talent, is when there are just too many applicants and very few positions to fill .e.g., freshers in satellite locations. There are limited fresher openings and if they go out accepting candidate profiles from everywhere, they will never be able to get through the interview process. So they prefer to go to top colleges, which are loose proxies for talent e.g., IITs in India. Even here, if you have a strong referral, you will get interviews regardless of whatever college you went to.
中文翻译
"最后,也是最基本的原因是,他们对自己的面试流程有着极大的信心。面试流程非常严格,只选择最充分准备的候选人。针对谷歌的面试准备是对你解决困难问题的真诚和专注的良好代表。
唯一需要使用松散的才能代理的情况是,申请者太多,可供填补的职位非常少,例如卫星地点的新毕业生。新毕业生的职位有限,如果他们接受来自各地的候选人档案,将无法通过面试流程。因此,他们更喜欢去顶尖学院,这些学院是才能的松散代理,例如印度的IIT。即使在这里,如果你有强大的内部推荐,你将获得面试机会,无论你上的是哪所大学。"
Summary: Nix the thought of talent. It’s a very limiting thought nor is it supported by research. Focus instead on making your profile presentable and more importantly, on preparing for the interview process.
Do let us know if you need help, our staff are ex-Google recruiters and they understand how interviewees succeed. Our typical audience is software engineers with anywhere from 0 to 40 years of experience, with a strong desire to uplevel their careers in a variety of ways. We have a lot of confidence in our methodology. Those who follow it even approximately to the tee succeed. Otherwise we’ll refund your fees.
We have cohorts starting every 2–3 weeks, but remain booked much in advance. If you’re interested, then please do plan early!
中文翻译
放弃对天赋的想法,这是一种非常限制性的思维,而且没有研究支持。相反,重点放在制作一个可呈现的个人资料上,更重要的是准备面试过程。
如果需要帮助,请告诉我们,我们的员工是前谷歌招聘人员,他们了解面试者如何成功。我们的典型受众是软件工程师,经验从0到40年不等,他们渴望以各种方式提升自己的职业生涯。我们对我们的方法非常有信心。那些遵循它即使近乎完美地成功。否则,我们将退还您的费用。
我们每2-3周开始一批新学员,但提前预订的名额有限。如果您感兴趣,请提前计划!
Is it true that many people in schools regard computer science students in universities as free computer repairers for granted, but what they learn is quite different from computer repair?
中文翻译
“是否有很多学校的人都认为大学的计算机科学专业学生可以免费为他们修理计算机,然而他们所学的与计算机维修完全不同?”
Yes and yes. And it’s not absurd; you might ask your English major friend for help editing a paper. It’s not necessarily a good idea, though, in both cases. I can guarantee that computer science students learn little to nothing about computer repair in the computer science courses (this isn’t necessarily true at a community college, though). If they know anything, it’s out of personal experience, interest, or a part-time job. And if you ask a friend for a favor, be respectful about it and either “pay back” when you can, or do something nice for them.
中文翻译
"是的,这是事实。这并不荒谬;你可能会向你的英语专业朋友寻求帮助来编辑一篇论文。但在这两种情况下,这未必是一个好主意。我可以保证,在计算机科学课程中,计算机科学专业的学生很少或几乎不学习与计算机维修有关的内容(尽管在社区大学可能不一样)。如果他们了解任何东西,那可能是出于个人经验、兴趣或兼职工作。如果你向朋友请求帮忙,请尊重对方,并在有机会时“回报”,或者为他们做一些好事。"