android 7 post,Android HTTP Post Request to IIS 7 Returns Bad Request(Invalid Header Name)

问题

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.

回答1:

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);

来源:https://stackoverflow.com/questions/7682514/android-http-post-request-to-iis-7-returns-bad-requestinvalid-header-name

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值