Chrome断网重连后再次客户端无感重发接口机制求解
If an HTTP/1.1 client sends a request which includes a request body, but which does not include an Expect request-header field with the "100-continue" expectation, and if the client is not directly connected to an HTTP/1.1 origin server, and if the client sees the connection close before receiving any status from the server, the client SHOULD retry the request.
大致意思就是说,如果发送一个请求到服务器端,该请求有请求体,但是请求头里面不包含“ 100-continue ”这种东西,并且客户端没有直接连接到原始的 HTTP/1.1 服务器,此时,如果客户端在接收到服务器发送的 HTTP 状态之前发现服务器连接断开(我们这边用拔网线模拟),那么客户端应该重试请求。
---------------以上为谷歌官方提供-----------------
服务端会在断网重连后重发这个接口,导致服务端出现两笔相同交易,经查证谷歌新版本存在断网重发机制,需要在head头添加( Expect: 100-continue)属性,但是:setRequestHeader 方法会报Refused to set unsafe header "Expect",W3C不允许客户端设置这种不安全的属性,现在浏览器和W3C矛盾了,断网重发机制没办法禁止掉,求指导类似的解决方法
交易控制应该在服务器端做,就是写入数据库前应该判断下这次请求的交易是否已经入库,而不是有通知就直接写数据库。
这个和微信支付成功后异步通知一样,需要自己写判断重复的通知,重复了直接输出操作成功的标志,而不是又写一次数据库。