ajax - Code 401 when issuing a POST request through Android -
when i'm accessing url postman works fine, through android i'm getting 401 error:
04-07 03:53:26.920 850-1142/system_process i/activitymanager: start u0 {cmp=vems.visioneering.com.vems/.utils.profileactivity} uid 10061 on display 0 04-07 03:53:26.957 26244-26244/vems.visioneering.com.vems v/action id: http://192.168.16.2:8081/vems/rest/ajax/getprofileobj 04-07 03:53:26.962 26244-26273/vems.visioneering.com.vems w/defaultrequestdirector: authentication error: unable respond of these challenges: {} 04-07 03:53:26.962 26244-26273/vems.visioneering.com.vems v/httpresponse: org.apache.http.message.basichttpresponse@83d69b6 04-07 03:53:26.962 26244-26273/vems.visioneering.com.vems v/status code: 401 04-07 03:53:26.963 26244-26244/vems.visioneering.com.vems d/androidruntime: shutting down vm
my code is:
try { defaulthttpclient client = new defaulthttpclient(); client.getparams().setparameter(clientpnames.allow_circular_redirects, true); httppost httppost = new httppost(params[1]); httppost.setheader("accept", "application/json"); httppost.setheader("content-type", "application/json"); stringentity entity = new stringentity(params[0]); httppost.setentity(entity); httpresponse httpresponse = client.execute(httppost); log.v("httpresponse ",httpresponse.tostring()); int statuscode = httpresponse.getstatusline().getstatuscode(); log.v("status code", string.valueof(statuscode)); if (statuscode == httpurlconnection.http_ok || statuscode == httpurlconnection.http_created) { httpentity httpentity = httpresponse.getentity(); response=entityutils.tostring(httpentity); log.v("response server comm : ",response); return response; } } catch (exception e){ // ... }
how solve this?
user session management additionally requires following header:
httppost.setheader("your code", "your code");
Comments
Post a Comment