标签: bad-request

Spring MVC请求正文错误处理

在使用@RequestBody StreamSourcefind out时,如果请求体中的xml无效StreamSource则会抛出异常(导致400 Bad Request)并且我无法处理它(告诉客户端什么是坏的).

有没有办法处理这种异常?

error-handling spring http spring-mvc bad-request

6
推荐指数
1
解决办法
5324
查看次数

Tomcat可以接受没有Host头的HTTP 1.1请求吗?

HTTP 1.1声明:"客户端必须在所有HTTP/1.1请求消息中包含主机头字段"

但是,我正在处理的机器会发出这个确切的POST(包含坐标),我无权更改:

POST /touch HTTP/1.1
Content-type: application/x-www-form-urlencoded
Content-Length: <n>

x=<int x>&y=<int y>
Run Code Online (Sandbox Code Playgroud)

400 Bad Request由于缺少Host头字段,Tomcat 7立即响应,POST永远不会到达我的servlet.有什么方法可以避免这个错误响应并使用servlet处理POST以支持这些旧机器吗?

tomcat hostheader bad-request http-1.1

6
推荐指数
1
解决办法
2827
查看次数

如何在Bad Request MVC时返回JSON对象

我正在研究MVC 4项目.

我有一个在Ajax Post请求完成时执行的Action.

在某些情况下,我可以确切地确定,我必须StatusResponse对象的属性设置为HttpBadRequestvalue,并返回包含一些数据的JSON对象以显示给最终用户.

问题是我无法在javascript方法中收到JSON对象,我正在接收其他内容.这是因为我将Response的Status属性设置为HttpBadRequest值.

这是细节

行动

// this method will executed when some Ajax Post request.
[HttpPost]
public ActionResult Delete(int id)
{
    // some code here ......

    // in some case we will determine an error like this
    if(error)
    {
        HttpContext.Response.Clear();
        HttpContext.Response.TrySkipIisCustomErrors = true;
        HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;

        return Json(new
        {
            Message = string.Format(format, values),
            Status = messageType.ToString()
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我想从这样的javascript函数中读取这个返回的JSON对象

使用Javascript

function OnDeleteFailed(data) {
    debugger;
    var try1 = $.parseJSON(data.responseText);
    var try2 …
Run Code Online (Sandbox Code Playgroud)

javascript c# model-view-controller json bad-request

6
推荐指数
1
解决办法
3646
查看次数

处理Rails ActionController :: BadRequest

所以,将要http://localhost:3000/%EDActionController::BadRequest.

但是如果返回404页面(就像大多数网站那样)我真正想要的是什么.

例如,Twitter会说:

一个或多个参数/%ED中的Unicode值无效

而我,我在开发中得到了它(生产中有500个错误页面):

去localhost:3000 /%ED

我尝试了显而易见rescue_from但错误甚至不是我的应用程序,因为它在路由堆栈中引发.

任何的想法?我想过中间件,但不知道我会怎么做?

ruby-on-rails http bad-request

5
推荐指数
1
解决办法
1104
查看次数

调试 400 Bad Request 响应

在我的 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}]}
Run Code Online (Sandbox Code Playgroud)

这在我的本地机器上按预期工作。但是,当我将应用程序部署到服务器时,完全相同的请求的响应看起来不同:

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
Run Code Online (Sandbox Code Playgroud)

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

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

iis json bad-request asp.net-mvc-4

5
推荐指数
1
解决办法
8119
查看次数

Delphi Google oauth2 令牌请求使用 Indy HTTP get 400 Bad Request

我正在尝试使用 oauth2 从 Google 请求访问和刷新令牌,我得到的只是“HTTP/1.1 400 错误请求”错误。

我在 Delphi XE5 中使用 IdHTTP 和 IdSSLIOHandlerSocketOpenSSL 处理程序。我有我的客户端 ID、客户端密钥和 API 密钥。我有授权码。

IdHTTP 配置为:

AllowCookies = True
HandleRedirects = True
HTTPOptions.hoKeepOrigProtocol = True
HTTPOptions.hoNoProtocolErrorException = True
Run Code Online (Sandbox Code Playgroud)

其他一切都是默认的。

有什么我应该事先做的事情吗,比如身份验证?

创建 Win32 应用程序时,redirect_uri 的相关性是什么?

将不胜感激地收到所有帮助。

这是我的代码:

var  Params: TStringList;
     Resp: TStringStream;
     URI: String;
begin

     Params := TStringList.Create;
     Resp := TStringStream.Create;

     try
        URI := 'https://accounts.google.com/o/oauth2/token';

        Params.Add('client_id=' + clientID);
        Params.Add('client_secret=' + clientSecret);
        Params.Add('code=' + authCode);
        Params.Add('redirect_uri=http://localhost');
        Params.Add('grant_type=authorization_code');

        IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
        IdHTTP.Post(URI, Params, Resp);

        Memo1.Lines.LoadFromStream(Resp);
        Memo1.Lines.Insert(0, IdHTTP.ResponseText);

        finally
        FreeAndNil(Params); …
Run Code Online (Sandbox Code Playgroud)

delphi indy bad-request access-token google-oauth

5
推荐指数
1
解决办法
5924
查看次数

GraphQL 上的 POST 返回 400 BAD REQUEST

我想发布一个更新字段“名称”的突变,它是 JSONString。当我这样做时,我得到了一个响应 - 400 BAD REQUEST,但是当我尝试其他突变(使用 String 字段类型)时,它变得顺利,结果正是我想要的。

function updateUserData() {
    var xhr = new XMLHttpRequest(),
        token = "BTNsngsfgfstnrw64wNsrgnws"

    var mutation = `mutation {
        addPosition( input: {
            name: "{\"pl\": \"Devlo\"}"
        }) {
            result {
                name
            }
        }
    }`;

$.ajax({
    beforeSend: (xhr) => xhr.setRequestHeader('Authorization', 'Basic ' + token),
    type: 'POST',
    url: 'http://46.17.113.45/graphql',
    data: JSON.stringify({ 'query': 'mutation { addPosition( input: { name: "{\\"p\\": \\"Develo\\"}" }) { result { name 
    contentType: 'application/json'
    }).done(function(response) {
        console.log(response)
});}
Run Code Online (Sandbox Code Playgroud)

在 GraphiQL 中,这种变异效果很好。返回值是查询中的确切内容。JSONString 和那些引号是否有问题,或者问题出在其他地方?令牌、类型、内容类型都很好 - 其他带有查询或突变的 POST …

bad-request graphql

5
推荐指数
1
解决办法
2万
查看次数

Asp.net MVC 核心错误请求 - 请求太长 HTTP 错误 400。请求头的大小太长

MVC 核心 2.0 Web 应用程序在浏览器中启动应用程序时遇到问题,它抛出错误请求 - 请求太长和 HTTP 错误 400,请求标头的大小太长。即使我清除了所有 cookie。第一次它将再次加载到错误的请求页面。

asp.net cookies bad-request asp.net-core

5
推荐指数
1
解决办法
5922
查看次数

在 ASP.NET Core 3.1 中向 HTTP 400 错误请求添加消息

有没有办法可以将消息添加到BadRequest操作结果中,并使该消息对外部客户端(例如 Postman)可见?我正在使用 ASP.NET Core 3.1。

\n\n

我的部分代码包含在下面。我想说的是问题是什么\xe2\x80\x94e.g.,id正文中发送的内容与从 URL 中获取的内容不同。现在,我正在使用Error我制作的一个对象,其中包含错误代码和消息。但当我发送请求时,这些在邮递员中不可见。

\n\n
public ActionResult PutColour(int id, Colour colour)\n{\n    if (id != colour.Id)\n    {\n        return BadRequest(new Error("IDNotTheSame","ID from URL is not the same as in the body."));\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

httprequest bad-request asp.net-core asp.net-core-webapi asp.net-core-3.1

5
推荐指数
1
解决办法
9461
查看次数

Twilio 频道 - SMS 60200 无效参数错误(400 错误请求)

我在 Twilio API 中收到“400 - 错误请求”错误,但找不到原因。

这是我的要求:

curl --location --request POST 'https://verify.twilio.com/v2/Services/xxxxxxxxxxxxxx/Verifications' \
--header 'Authorization: Basic xxxxxxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Channel=sms' \
--data-urlencode 'To=+44xxxxxxxxxx'
Run Code Online (Sandbox Code Playgroud)

我收到回复:

curl --location --request POST 'https://verify.twilio.com/v2/Services/xxxxxxxxxxxxxx/Verifications' \
--header 'Authorization: Basic xxxxxxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Channel=sms' \
--data-urlencode 'To=+44xxxxxxxxxx'
Run Code Online (Sandbox Code Playgroud)

响应包含RequestID标头,但在 Twilio 门户中无法通过 查找错误RequestID

bad-request http-status-code-400 twilio-api

5
推荐指数
1
解决办法
2900
查看次数