i'm trying sign in user dreamfactory api doing post erquest new session token. i'm getting volley tileout error...
here code:
public void getusertoken(view view){ final edittext edittext_username = (edittext)view.findviewbyid(r.id.username_name_edittext); final edittext edittext_password = (edittext)view.findviewbyid(r.id.password_name_edittext); requestqueue queue = volley.newrequestqueue(getcontext()); string url = "http://my.virtual.machine/rest/user/session"; jsonobject js = new jsonobject(); try { js.put("email", edittext_username.gettext().tostring()); js.put("password", edittext_password.gettext().tostring()); } catch (jsonexception e) { e.printstacktrace(); } jsonobjectrequest usertokenrequest = new jsonobjectrequest(request.method.post, url,js, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { try { usertoken = response.getstring("session_id"); useremail = response.getstring("email"); log.d("usertoken response", "ok => " + usertoken); getuserdata(); } catch (jsonexception e) { e.printstacktrace(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { // todo auto-generated method stub log.d("error","error => "+error.tostring()); } } ) { @override public map<string, string> getheaders() throws authfailureerror { map<string, string> params = new hashmap<string, string>(); params.put("x-dreamfactory-application-name", "xxx"); return params; } }; queue.add(usertokenrequest); }
when run post request hurl.it works fine...
found problem, response takes time do, adding delay works! :)
int sockettimeout =5000;//5 seconds - change want retrypolicy policy = new defaultretrypolicy(sockettimeout, defaultretrypolicy.default_max_retries, defaultretrypolicy.default_backoff_mult); usertokenrequest.setretrypolicy(policy); queue.add(usertokenrequest);
Comments
Post a Comment