Android: HTTP POST response - 401 -


i have faced 1 problem - returning 401 error msg when signed in , trying access secured pages. mystic of problem me can access secured pages after signed in if check via firefox restclient or via ios app cannot access via chrome advanced rest client , android app. however, content-type , other necessary params set same in both web tools , apps. have tried set different auth headers encoded login:pass doesnt , doesnt need because should work without it, think(at least ff , ios app work without header). what`s gonna wrong?

response headers of chrome:

401 unauthorized  loading time: 29 request headers content-type: application/x-www-form-urlencoded  response headers date: mon, 04 mar 2013 10:01:02 gmt  server: apache/2.2.20 (ubuntu)  x-powered-by: php/5.3.6-13ubuntu3.9 set-cookie: peachy=qg3mjvchjh1oionqlhhv0jrn71; path=/  expires: thu, 19 nov 1981 08:52:00 gmt  cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0  pragma: no-cache  vary: accept-encoding  content-length: 96  keep-alive: timeout=5, max=100 connection: keep-alive content-type: text/html; charset=utf-8  

response headers of firefox:

status code: 200 ok cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 connection: keep-alive content-length: 202 content-type: application/json date: mon, 04 mar 2013 09:51:09 gmt expires: thu, 19 nov 1981 08:52:00 gmt keep-alive: timeout=5, max=100 pragma: no-cache server: apache/2.2.20 (ubuntu) x-powered-by: php/5.3.6-13ubuntu3.9 

that peace of restful code in android app:

public string serverrequest(int action, bundle params) {     if (action == 0) {         if (const.debug_enabled)             log.e(tag, "you did not pass action.");         return "you did not pass action.";     }      try {         httprequestbase request = null;         httppost postrequest = null;         switch (action) {             case sign_in:                 request = new httppost();                 request.seturi(new uri(signin_url));                 request.setheader("content-type", "application/x-www-form-urlencoded; charset=utf-8");                   postrequest = (httppost) request;                   if (params != null) {                  urlencodedformentity formentity = new                  urlencodedformentity(paramstolist(params));                  postrequest.setentity(formentity);                  }                 break;              case sign_out:                 request = new httppost();                 request.seturi(new uri(signout_url));                 request.setheader("content-type", "application/x-www-form-urlencoded; charset=utf-8");                 break;              case bank_card_verify:                 request = new httppost();                 request.seturi(new uri(bank_card_verify_url));                 request.setheader("content-type", "application/x-www-form-urlencoded; charset=utf-8");                  postrequest = (httppost) request;                  if (params != null) {                     urlencodedformentity formentity = new urlencodedformentity(paramstolist(params));                     postrequest.setentity(formentity);                 }                 break;         }          if (request != null) {             defaulthttpclient client = new defaulthttpclient();              if (const.debug_enabled)                 log.d(tag, "executing request: " + actiontostring(action) + ": " + urltostring(action));              httpresponse response = client.execute(request);              statusline responsestatus = response.getstatusline();              int statuscode = responsestatus != null ? responsestatus.getstatuscode() : 0;             log.d(tag, "status code: " + statuscode);             }             } 

(sign in , sign out public, bank_verify secured page. android app has same response headers chrome). seems there problem session or else i`m not sure exactly.

edit: seems have found what`s problem here. in android app create new httpclient object due old data losed. question - how make httpclient reusable?

problem found. reuse httpclient everytime in spite of use 1 has session data everytime. implement if statement check if have httpclient object otherwise create new.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -