对IIS 7的Android HTTP发布请求返回错误请求(无效的标题名称)

Mik*_* L. 0 android amazon-ec2 iis-7.5 http-status-code-400 asp.net-mvc-3

我在Amazon EC2实例上托管了MVC 3 Web服务.我有一个Android应用程序正在向服务发出请求.但是,返回400错误请求,表示标题名称无效.我检查了服务器上的日志,并且请求没有进入IIS.HTTP Err Log只包含以下条目:

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上创建发布请求的代码:

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

任何见解都表示赞赏.

谢谢.

spa*_*nia 6

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

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