标签: bad-request

在Flask应用程序中提交表单时,错误请求错误的原因是什么?

在阅读了许多类似的声音问题和相关的Flask文档之后,我似乎无法弄清楚在提交表单时会产生以下错误:

400错误请求

浏览器(或代理)发送了此服务器无法理解的请求.

虽然表单总是正确显示,但当我提交与这些函数中的任何一个相关联的HTML表单时,会发生错误请求:

@app.route('/app/business', methods=['GET', 'POST'])
def apply_business():
    if request.method == 'POST':    
        new_account = Business(name=request.form['name_field'], email=request.form['email_field'], account_type="business", 
            q1=request.form['q1_field'], q2=request.form['q2_field'], q3=request.form['q3_field'], q4=request.form['q4_field'], 
            q5=request.form['q5_field'], q6=request.form['q6_field'], q7=request.form['q7_field'],
            account_status="pending", time=datetime.datetime.utcnow())
        db.session.add(new_account)
        db.session.commit()
        session['name'] = request.form['name_field']    
        return redirect(url_for('success'))
    return render_template('application.html', accounttype="business")          

@app.route('/app/student', methods=['GET', 'POST'])
def apply_student():    
    if request.method == 'POST':    
        new_account = Student(name=request.form['name_field'], email=request.form['email_field'], account_type="student", 
            q1=request.form['q1_field'], q2=request.form['q2_field'], q3=request.form['q3_field'], q4=request.form['q4_field'], 
            q5=request.form['q5_field'], q6=request.form['q6_field'], q7=request.form['q7_field'], q8=request.form['q8_field'], 
            q9=request.form['q9_field'], q10=request.form['q10_field'],
            account_status="pending", time=datetime.datetime.utcnow())
        db.session.add(new_account)
        db.session.commit()
        session['name'] = request.form['name_field']    
        return redirect(url_for('success')) 
    return render_template('application.html', accounttype="student")
Run Code Online (Sandbox Code Playgroud)

HTML的相关部分是

<html>
<head>
    <title>apply</title>
</head>
<body>
    {% …
Run Code Online (Sandbox Code Playgroud)

python forms post bad-request flask

75
推荐指数
1
解决办法
7万
查看次数

MVC控制器返回错误的请求?

我想知道是否有可能从MVC控制器返回一个带有内容的错误请求?我能够做到这一点的唯一方法是在throw HttpException这里我不能设置任何内容.试过这种方法,但由于一些奇怪的原因,我总是得到回报.是否有可能做到这一点?

public class SomeController : Controller
{
    [HttpPost]
    public async Task<HttpResponseMessage> Foo()
    {
        var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
        response.Content = new StringContent("Naughty");

        return response;    
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc bad-request asp.net-mvc-4

37
推荐指数
4
解决办法
6万
查看次数

Android HttpClient和HTTPS

我刚开始在Android中实现HTTPS连接.本质上,我正在尝试使用org.apache.http.client.HttpClient连接到服务器.我相信,在某些时候,我需要访问应用程序的密钥库,以便使用私钥授权我的客户端.但是,目前,我只是试图联系,看看会发生什么; 我一直收到HTTP/1.1 400 Bad Request错误.

尽管有许多例子(似乎没有一个对我有用),我似乎无法做出这方面的正面或反面.我的代码看起来像这样(BODY常量是XmlRPC):

 private void connect() throws IOException, URISyntaxException{

    HttpPost post     = new HttpPost(new URI(PROD_URL));
    HttpClient client = new DefaultHttpClient();

    post.setEntity(new StringEntity(BODY));
    HttpResponse result = client.execute(post);

    Log.d("MainActivity", result.getStatusLine().toString());

}
Run Code Online (Sandbox Code Playgroud)

所以,非常简单.如果有人有任何建议,请告诉我.谢谢!

ssl https android httpclient bad-request

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

返回空ActionResult

当我需要返回错误的请求结果时,我可能会遇到情况.

例如,调用MVC 3站点的控制器操作,但请求uri中缺少必需的参数.

我回复了什么?我知道我可以这样做:

Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content(string.Empty);
Run Code Online (Sandbox Code Playgroud)

这是上述情况的正确方法吗?

asp.net-mvc bad-request actionresult

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

Guzzle:处理400个不良请求

我在Laravel 4中使用Guzzle从另一台服务器返回一些数据,但我无法处理Error 400错误请求

 [status code] 400 [reason phrase] Bad Request
Run Code Online (Sandbox Code Playgroud)

使用:

$client->get('http://www.example.com/path/'.$path,
            [
                'allow_redirects' => true,
                'timeout' => 2000
            ]);
Run Code Online (Sandbox Code Playgroud)

怎么解决?谢谢,

php bad-request laravel guzzle

19
推荐指数
2
解决办法
3万
查看次数

修复错误的引用网址

我最近注意到来自外部网站的错误网址到我的网站.

我从使用以下错误链接引用我的网站的网站中找不到大量404:

我的网站 - http://www.example.com/mypage/CachedOnTuesdays

我的链接应该是:http://www.example.com/mypage/

我知道我不能要求他们解决它.有没有办法删除URL的最后一部分以显示正确的页面?

url external bad-request http-status-code-404

17
推荐指数
1
解决办法
516
查看次数

WebClient - 获取错误状态代码的响应正文

我基本上都在寻找同样的问题: 当服务器返回错误时,使用WebClient访问响应体的方法是什么?

但到目前为止还没有提供任何答案.

服务器返回"400错误请求"状态,但有详细的错误说明作为响应正文.

有关使用.NET WebClient访问该数据的任何想法?它只是在服务器返回错误状态代码时抛出异常.

c# webclient bad-request

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

如何在 cypress 中测试错误的请求

我正在使用不正确的凭据测试在 cypress 中登录 POST 方法。这将返回 400 个我需要测试的错误请求。

这就是我所拥有的:

describe('Login API Test - Correct user login', () => {
  it('Validate the header', () => {
    cy.request({
      method: 'POST',
      url: 'https://myrAPI',
      auth: {
        username: 'user@user',
        password: 'user123',
      },
      headers: {
        'Authorization': 'Basic dXNlckB1c2VyOnVzZXI=',
        'Content-Type': 'text/plain'
      }
    }).then((response) => {
      // expect(response.body).to.exist // true
      // expect(response.body).('User.Access: Exception occured:User.Access : CheckUser: Exception occurred:Error with Authentication Header. result =') // true
      // expect(response.headers).should.contain('text/plain; charset=utf-8')
      // expect(response.body).statusCode.should.equal(400)
      response.status.should.equal(400)
      //expect(response).to.have.property('headers')
    })
  }})
Run Code Online (Sandbox Code Playgroud)

发送的请求:

Method: POST
URL: https://myapi …
Run Code Online (Sandbox Code Playgroud)

javascript testing bad-request cypress

13
推荐指数
2
解决办法
8765
查看次数

如何在nginx中处理"OPTIONS*"请求?

在我的环境中,我使用perlbal将请求重定向到nginx.如果启用了verify_backend.perbal会向nginx发送一个"OPTIONS*"请求,但是nginx会将其作为一个错误的请求进行响应.

根据RFC2616:

如果Request-URI是星号(" "),则OPTIONS请求通常应用于?服务器而不是特定资源.由于服务器的通信选项通常取决于资源,因此" "请求仅用作"ping"或"no-op"类型的方法; 除了允许客户端测试服务器的功能之外,它什么都不做.例如,这可以用于测试HTTP/1.1合规性(或缺乏)的代理.

我认为perlbal试图发送这种请求,但是nginx默认不能处理这个问题.

当我尝试发送请求"OPTIONS*HTTP/1.0"时,我总是得到"HTTP 400错误请求":

127.0.0.1 - - [18/Feb/2013:03:55:47 +0000]"OPTIONS*HTTP/1.0"400 172" - "" - "" - "

但它适用于没有星号请求的"OPTIONS/HTTP/1.0"选项:

127.0.0.1 - - [18/Feb/2013:04:03:56 +0000]"OPTIONS/HTTP/1.0"200 0" - "" - "" - "

如何配置nginx以使其响应http返回200而不是HTTP返回400?

http nginx bad-request http-options-method

12
推荐指数
1
解决办法
5668
查看次数

Tomcat 没有重定向到 400 bad request 自定义错误页面

我们在生产中有 tomcat 9 Web 服务器。我们面临的问题是,如果 tomcat 收到任何格式错误的 URL,我们希望为我们的应用程序显示自定义错误页面,如下所示

http://网址/|

或者

http://网址/[

我在tomcat应用服务器的web.xml中添加了error page标签如下

<error-page>
   <error-code>400</error-code>
   <location>/error.html</location>
 </error-page>
 <error-page>
   <error-code>404</error-code>
   <location>/error.html</location>
 </error-page>
Run Code Online (Sandbox Code Playgroud)

我们在tomcat的webapps目录下的应用程序ROOT文件夹中有error.html。

每当用户尝试请求任何不存在的网页时,他都会收到与上面指定的 404 错误代码正确对应的错误页面。

真正的问题是当用户在浏览器中输入格式错误的 URL(如http://URL/|)时,tomcat 无法重定向到 error.html

Tomcat 显示的是默认的 400 bad request 错误页面,而不是自定义错误页面。

redirect tomcat bad-request tomcat9

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