java - Android Volley Request not sending POST data to server/database -
i developing android app have been trying incorporate social media login, trying add details retrieved via social media login (name & email) , add database of users on our server via volley request. far have managed users details succesfully , add shared preferences using 'session' class created, calling method send data server not work.
facebookloginbutton.registercallback(callbackmanager, new facebookcallback<loginresult>() { string fbid = null; string fbname = null; string fbemail = null; @override public void onsuccess(loginresult loginresult) { graphrequest request = graphrequest.newmerequest( loginresult.getaccesstoken(), new graphrequest.graphjsonobjectcallback() { @override public void oncompleted( jsonobject object, graphresponse response) { try { fbid = object.getstring("id"); fbname = object.getstring("name"); fbemail = object.getstring("email"); session.setlogin(true); session.setuserdetails(fbemail,fbname); } catch (jsonexception e) { e.printstacktrace(); } { registersocialuser(fbname, fbemail); } } });
as can see in try/catch make request registersocialuser() method via 'finally' block. calls following method fine , console log's users details, never added database.
private void registersocialuser (final string name, final string email) { requestqueue queue = volley.newrequestqueue(this); stringrequest request = new stringrequest(request.method.post, config.register_social_url, new response.listener<string>() { @override public void onresponse(string response) { log.d("creation", "social media account added: " + name + " " + email); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.d("creation", "create error"); } }) { @override protected map<string, string> getparams() { map<string, string> params = new hashmap<>(); params.put("user",name); //name params.put("email",email); //email return params; //return parameters } }; queue.add(request); log.d("creation", "success"); }
the logcat returns:
social media account added: *my name* *my email*
the config.register_social_url php file takes 2 post parameters (name , email) , adds them database after checking doesn't exist. can call manually through browser same details , works fine , adds database.
excuse me if of code bad practice, i'm pretty new android development appreciate :)
while sending parameters can use post request method. there plenty of chances have been missing method.
private void registersocialuser (final string name, final string email) { requestqueue queue = volley.newrequestqueue(this); string stoparchiveurl = config.register_social_url; stringrequest stringrequest = new stringrequest(request.method.post, stoparchiveurl, new response.listener<string>() { @override public void onresponse(string response) { log.d("creation", "social media account added: " + name + " " + email); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.d("error", "error adding social media account"); } }){ @override protected map<string, string> getparams() { map<string, string> params = new hashmap<>(); params.put("name",name); //name params.put("email",email); //email return params; //return parameters } }; // add request requestqueue. queue.add(stringrequest); intent intent = new intent(loginactivity.this, mainactivity.class); startactivity(intent); finish();
}
i think problem not lies in code. strings passing in parameters while using post, using
params.put("user",name); //name
which should
params.put("name",name); //name
also better if attach token using secret key validation on server side too. so, no 1 hit url (if leaked somehow) anonymously.
Comments
Post a Comment