Android HTTP Post 请求到 IIS 7 返回错误请求(无效标头名称)
我有一个 MVC 3 Web 服务托管在 Amazon EC2 实例上。我有一个 Android 应用程序正在向该服务发出发布请求。但是,会返回 400 bad 请求,表示标头名称无效。我检查了服务器上的日志,请求未进入 IIS。 HTTP 错误日志仅包含以下条目:
2011-10-07 02:01:05 xxx.xxx.xx.xx xxxxx xx.xxx.xx.xx 80 HTTP/1.1 POST /API/UserAccount/Login 400 - 标头 -
否真的很确定发生了什么事。我在Visual Studio自带的开发服务器上测试了这个Web服务,没有任何问题。以下是在 Android 上创建 post 请求的代码:
HttpPost post = new HttpPost(LOGIN_URL);
StringEntity se = new StringEntity(json);
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
post.setEntity(se);
response = client.execute(post);
如有任何见解,我们将不胜感激。
谢谢。
I have a MVC 3 Web Sevice being hosted on an Amazon EC2 Instance. I have an android app that is making a post request to the service. However a 400 bad request is returned saying that the header name is invalid. I checked the logs on the server and the request does not make it into IIS. The HTTP Err Log just has these entries:
2011-10-07 02:01:05 xxx.xxx.xx.xx xxxxx xx.xxx.xx.xx 80 HTTP/1.1 POST /API/UserAccount/Login 400 - Header -
Not really sure what is going on. I tested this web service on the developement server that comes with visual studio and there was no problems. Here is the code that creates the post request on Android:
HttpPost post = new HttpPost(LOGIN_URL);
StringEntity se = new StringEntity(json);
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
post.setEntity(se);
response = client.execute(post);
Any insight is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改设置 Http 标头的方式。这是您的代码的更新版本:
Change the way you're setting the Http headers. Here's an updated version of your code: