AJAX 在不同浏览器上调用的间歇性 411 错误

Intermittent 411 error for AJAX call on different browsers

我有一个旧的 C# MVC 4.7 网络应用程序,它有一个特定的 $.post 调用。 运行 本地从 Visual Studio 2019 在任何浏览器中,我完全没有问题。调用通过,post 将部分页面按预期发送到 div。 运行 来自我们的测试 URL,它在 Edge 和 Chrome 中给我一个错误,但在 Firefox 中没有。它 returns 一个 411 错误,我知道这意味着这是一个内容长度问题。问题是访问该站点的其他人不会 运行 在任何浏览器中解决该问题。由于它适用于其他人的机器和我本地机器上的一个特定浏览器,我怀疑它是一个安全设置或该特定站点的类似内容。我已经清除了设置,重置为出厂默认设置,删除了扩展程序,确保 up-to-date 并在使用和不使用防病毒软件交互的情况下对其进行了测试。

这失败了:

$.post('/Controller/Method', function (data) {
                $('#container').html(data);
            });

但这行得通:

$.post("/Controller/OtherMethod", { paramOne: varOne, paramTwo: varTwo }, function (data) {

                    $("#container").html(data);

                });

从测试 运行 测试 URL 时,这两个功能都在 Firefox 中工作,只有第二个功能在测试 URL 的 Edge/Chrome 中工作。

关于我可能需要检查的内容有什么想法吗?

这是 Dev Tools 中失败调用的 header:

  • General

Request URL: https://[url]/Controller/Method?param=123

Request Method: POST

Status Code: 411

Remote Address: [remote_ip]

Referrer Policy: strict-origin-when-cross-origin

  • Response Headers

content-type: text/html; charset=us-ascii

date: Thu, 19 Aug 2021 17:08:18 GMT

server: Microsoft-HTTPAPI/2.0

  • Request Headers

:authority: [url]

:method: POST

:path: Controller/Method?param=123

:scheme: https

accept: /

accept-encoding: gzip, deflate, br

accept-language: en-US,en;q=0.9

cache-control: no-cache

content-length: 0

cookie: [cookie info]

origin: https://[url]

pragma: no-cache

referer: https://[url]/Controller/Method?param=123

sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"

sec-ch-ua-mobile: ?0

sec-fetch-dest: empty

sec-fetch-mode: cors

sec-fetch-site: same-origin

user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

x-requested-with: XMLHttpRequest

在两个不同网站的 Chrome 和 Edge 中遇到同样的问题后,我想我找到了答案:

问题似乎是 BitDefender 防病毒软件。

如果我禁用 BitDefender 保护,post 请求会成功。

编辑: 奇怪的是,如果我随后重新启用 BitDefender 保护,问题就不会再出现了。

在摸索出解决方案后,我找到了一些有同样问题的人的参考资料:https://community.bitdefender.com/en/discussion/88573/status-411-length-required-during-browsing https://support.mozilla.org/en-US/questions/1344632