开发者

android httpclient post after login to sever

开发者 https://www.devze.com 2023-03-27 08:53 出处:网络
My problem is that I have successfully login to my Rail sever with HTTP Post. And I also get the response object, toString the Entity.

My problem is that I have successfully login to my Rail sever with HTTP Post.

And I also get the response object, toString the Entity.

response =  httpclient.execute(post);
r_entity = response.getEntity();
String responseString = EntityUtils.toString(r_entity);
Log.d("UPLOAD_MAIL_LOGIN", responseString);

Successfully got the login html code.(which means I have logged in.)

However, when I start to POST something through this client(just after I logined),

my Log just show that I have logout already. The sever has rendered me back to the login page. (The strange part is that I just get that page's html code to insure I'm still in login status)

HttpGet get_new = new HttpGet("http://myseverblabla.heroku.com/clips/new");
response =  httpclient.execute(get_new);
HttpEntity n_entity = response.getEntity();
String responseString = EntityUtils.toString(n_entity);
Log开发者_Python百科.d("UPLOAD_MAIL_NEW_MSG", responseString);           
This part worked very well.



HttpPost post_send = new HttpPost("http://vocal-clp.heroku.com/clips/");

MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("clip[receiver_id]", new StringBody(phoneNumber.getText().toString()));
...
...
...

multipartEntity.addPart("clip[audio]", new FileBody(recodeFile));  
//This is an audio file.
post_send.setEntity(multipartEntity);           
response = httpclient.execute(post_send);
HttpEntity s_entity = response.getEntity();
responseString_s = EntityUtils.toString(s_entity);
Log.d("UPLOAD_MAIL_SEND", responseString_s);   

This UPLOAD_MAIL_SEND Log show that I just back to the login page.

My problem is :

1.Is there any limitation about httpclient, like you can't post something directly? 2.I have tried another sever, which doesn't has account system, it worked fine. The file and text is uploaded.


I'm sure that I typed the object[content] entity well(Checked and compared by reading two severs rails log)

These question has bothered me for many days, hope someone can help me with it.

Thanks!


How do you configure your HttpClient and where does it come from?

If it's an AndroidHttpClient then it doesn't retain cookies by default, which would cause the session to be lost, see the doc for the solution : http://developer.android.com/reference/android/net/http/AndroidHttpClient.html and let me know...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号