为什么我收到Http/1.1 400错误的请求? [英] Why am I getting Http/1.1 400 Bad request?

查看:246
本文介绍了为什么我收到Http/1.1 400错误的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码的摘要.我正在尝试使用HTTPOST登录该网站.

Here is a snippet of my code. I am trying to login to the website using HTTPOST.

我不断收到"400错误请求"我尝试了各种组合.我尝试将用户名/密码作为标头而不是NameValuePair传递.但结果相同.有什么我想念的吗?

I keep getting "400 Bad Request" I have tried various combinations. I tried passing username/password as header instead of NameValuePair. But same result. Is there something I am missing?

HttpClient httpclient = new DefaultHttpClient();
        
HttpPost post = new HttpPost("https://identi.ca/main/login");
    

List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("nickname", u));
nvps.add(new BasicNameValuePair("password", p));
nvps.add(new BasicNameValuePair("submit", "Login"));

post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

HttpResponse response = httpclient.execute(post);
HttpEntity entity = response.getEntity();

Log.i("Login form POST result: ", response.getStatusLine().toString());
        

感谢您的帮助.

推荐答案

如果HTTP服务认为您发送的是无效/错误/不当内容,则会发送400响应.无法从您的代码中得知实际发送的参数是什么,或者(更重要的是)服务器希望您发送的参数.

A HTTP service will send a 400 response if it thinks you have sent an invalid / incorrect / inappropriate. There is no way to tell from your code, what the actual arguments sent will be, or (more important) what the server expects you to send.

要对此进行诊断,您将需要:

To diagnose this you will need to:

  • 找出您的代码实际发送的内容,并且
  • 找出服务器希望您发送的内容.

第二个可能涉及:

  • 查看具有网络浏览器的普通用户用来发出请求的网页,
  • 查看您从服务器获得的400条响应的正文,
  • 查看服务器日志,和/或
  • 查看服务器的Web API文档(或源代码).

在这种情况下,似乎需要提供一个额外的 token 参数.

In this case, it looks like there is an extra token parameter that needs to be supplied.

但是,我怀疑您可能完全采用了错误的方法."identi.ca"站点使用StatusNet,该网络具有两个已发布的API 用于客户端.没有提及我能看到的登录" URL.

However, I suspect that you might be taking the wrong approach entirely. The "identi.ca" site uses StatusNet which has a couple of published APIs for clients. There's no mention of talking to the "login" URL that I could see.

这篇关于为什么我收到Http/1.1 400错误的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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