到IIS 7的Android HTTP发布请求返回错误的请求(无效的标头名称) [英] Android HTTP Post Request to IIS 7 Returns Bad Request(Invalid Header Name)

查看:82
本文介绍了到IIS 7的Android HTTP发布请求返回错误的请求(无效的标头名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC 3 Web服务托管在Amazon EC2实例上.我有一个向该服务发出发布请求的android应用.但是,将返回一个400错误的请求,说明标头名称无效.我检查了服务器上的日志,但该请求没有进入IIS. HTTP错误日志仅包含以下条目:

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-标头-

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 -

不太确定发生了什么.我在Visual Studio附带的开发服务器上测试了此Web服务,没有任何问题.这是在Android上创建发布请求的代码:

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.

谢谢.

推荐答案

更改设置Http标头的方式.这是您代码的更新版本:

Change the way you're setting the Http headers. Here's an updated version of your code:

HttpPost post = new HttpPost(LOGIN_URL);
StringEntity se = new StringEntity(json);
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
post.setEntity(se);
response = client.execute(post);

这篇关于到IIS 7的Android HTTP发布请求返回错误的请求(无效的标头名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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