Reputation: 589
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.
Upvotes: 0
Views: 3787
Reputation: 6663
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);
Upvotes: 6