android - http post content-length (json post) -


i need create post request user login. setting content-length header when post request gives org.apache.http.client.httpresponseexception: length required

my code

        defaulthttpclient httpclient = new defaulthttpclient();          jsonobject data = new jsonobject();         data.put("username", username);         data.put("password", password);         data.put("rememberme", false);          httppost httpost = new httppost(login_path);         stringentity se = new stringentity(data.tostring());         httpost.setentity(se);          httpost.setheader("accept", "application/json");         httpost.setheader("content-type", "application/json");         httpost.setheader("content-length",""+se.getcontentlength());          responsehandler responsehandler = new basicresponsehandler();         return httpclient.execute(httpost, responsehandler); 

when set content-length header gives 'content-length header present' , , when remove content-lenght header gives 'length required'

thanks.

change

 httpost.setheader("content-lenght",""+se.getcontentlength()); 

to

 httpost.setheader("content-length",""+se.getcontentlength()); 

because passing content-lenght (length spelling mistake) instead of content-length key setheader method


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -