gpt4 book ai didi

json - 调试 400 Bad Request 响应

转载 作者:行者123 更新时间:2023-12-04 23:02:53 24 4
gpt4 key购买 nike

在我的 MVC 应用程序中,当一个 POST 请求被发送到服务器(通过 jQuery)并且发生验证错误时,会返回一个 400 Bad Request,正如预期的那样:

HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
Date: Thu, 26 Feb 2015 08:35:50 GMT
Content-Length: 174

{"ReturnValue":null,"Results":[{"Message":"The xyz field is required.","ErrorNumber":123,"Severity":1}]}

这在我的本地机器上按预期工作。但是,当我将应用程序部署到服务器时,完全相同的请求的响应看起来不同:
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Date: Thu, 26 Feb 2015 08:37:01 GMT
Content-Length: 24

Invalid Request

注意内容类型是 text/html ,并且响应正文不再包含 JSON。

这可能是什么原因?我会很感激一个指针从哪里开始调试。

最佳答案

在进一步搜索和阅读后,我在 this post 中找到了答案。这也引用了有用的文章 IIS 7 Error Pages taking over 500 Errors

问题是 IIS 接受了 400 多个错误请求错误,并用 IIS 错误内容替换了我的自定义 JSON 响应。可以使用 TrySkipIisCustomErrors 禁用此行为。环境:

Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 400;

关于json - 调试 400 Bad Request 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28738050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com