如何从Web表单请求返回HTTP 400-错误请求错误? [英] How do I return an HTTP 400 - Bad Request error from a web form request?

查看:251
本文介绍了如何从Web表单请求返回HTTP 400-错误请求错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主题几乎说明了一切.我有一个EstateReport Web表单,必须使用EstateId请求参数来调用它.我想返回一个适当的HTTP错误是我们不存在此参数.如何返回HTTP错误400作为响应?

在切线上,如果所需参数不存在(我觉得更正确),还是应该重定向到报表的搜索页面(更方便用户),我应该返回错误吗?

解决方案

因此,据我了解,表单需要一个参数来以有意义的方式显示结果. 400是一个错误请求,据我了解您的想法,该规范指出:

由于语法格式错误,服务器无法理解该请求.客户端不应在未经修改的情况下重复该请求."

从最纯粹的意义上讲,如果有人要求说不带参数的"EstateReport.aspx",则服务器仍然可以解释该错误并以适当的响应进行回复,因此从广义上讲它不是一个不好的请求".

我的建议是,您检测到该参数的缺失,并通过页面链接呈现适当的错误消息,在该页面上,他们可以通过某种方式选择适当的"estateId",因此当请求EstateReport时,该参数就存在.

The subject pretty much says it all. I have an EstateReport web form that must be called with an EstateId request parameter. I want to return an appropriate HTTP error is this parameter us not present. How do I return an HTTP error 400 as my response?

On a tangent, should I return an error if the required parameter isn't present, which I feel is more correct, or redirect to the search page for the report, which is more user friendly?

解决方案

So from what I understand the form requires a parameter to display results in a meaningful way. A 400 is a Bad Request, while I understand your thinking, the specification states:

"The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications."

In its purest sense, if someone requests say "EstateReport.aspx" without a parameter, the server can still interpret this and reply with an appropriate response, so its not a "bad request" in its broadest sense.

What I would suggest is you detect the absence of the parameter and render an appropriate error message with a link to a page where they could select an appropriate "estateId" via some way, so when EstateReport is requested, the parameter is present.

这篇关于如何从Web表单请求返回HTTP 400-错误请求错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆