please m creating login page using code .which authenticate after matching url value user name , password
and java code,
public class androidhttprequestsactivity extends activity implements onclicklistener { private edittext usernameedittext; private edittext passwordedittext; private button sendgetreqbutton; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); usernameedittext = (edittext) findviewbyid(r.id.main_username_edittext); passwordedittext = (edittext) findviewbyid(r.id.main_password_edittext); sendgetreqbutton = (button) findviewbyid(r.id.main_sendgetreq_button); sendgetreqbutton.setonclicklistener(this); } public void onclick(view v) { if(v.getid() == r.id.main_sendgetreq_button) { // values given in edittext fields string givenusername = usernameedittext.gettext().tostring(); string givenpassword = passwordedittext.gettext().tostring(); system.out.println("given usernames :" + givenusername + " given password :" + givenpassword); // pass values connectwithhttpget() method connectwithhttpget(givenusername, givenpassword); } } private void connectwithhttpget(string givenusername, string givenpassword) { class httpgetasynctask extends asynctask<string, void, string> { @override protected string doinbackground(string... params) { string email = params[0]; string pwd = params[1]; system.out.println("email :" + email + " pwd :" + pwd); httpclient httpclient = new defaulthttpclient(); httpget httpget = new httpget("http://ipadress/folder/filename.php?command=cmd_login&email=name&pwd=00"); try { httpresponse httpresponse = httpclient.execute(httpget); system.out.println("httpresponse"); // comes httpresponse inputstream inputstream = httpresponse.getentity().getcontent(); inputstreamreader inputstreamreader = new inputstreamreader(inputstream); bufferedreader bufferedreader = new bufferedreader(inputstreamreader); stringbuilder stringbuilder = new stringbuilder(); string bufferedstrchunk = null; while((bufferedstrchunk = bufferedreader.readline()) != null){ stringbuilder.append(bufferedstrchunk); } system.out.println("returning value of doinbackground :" + stringbuilder.tostring()); return stringbuilder.tostring(); } catch (clientprotocolexception cpe) { system.out.println("exception generates caz of httpresponse :" + cpe); cpe.printstacktrace(); } catch (ioexception ioe) { system.out.println("second exception generates caz of httpresponse :" + ioe); ioe.printstacktrace(); } return null; } @override protected void onpostexecute(string result) { super.onpostexecute(result); if(result.equals("1")) { toast.maketext(getapplicationcontext(), "http working...", toast.length_long).show(); }else{ toast.maketext(getapplicationcontext(), "invalid...", toast.length_long).show(); } } } httpgetasynctask httpgetasynctask = new httpgetasynctask(); httpgetasynctask.execute(givenusername, givenpassword); } } and response in logcat this. how match result value show login sucess
if(result.equal("")) what should compare result? tried value==1, doesn't work.
07-19 13:54:26.509: i/system.out(13951): given usernames :name given password :00 07-19 13:54:26.519: i/system.out(13951): email :name pwd :00 07-19 13:54:27.689: i/system.out(13951): httpresponse 07-19 13:54:27.689: i/system.out(13951): returning value of doinbackground :<?xml version="1.0" encoding="iso-8859-1"?><command><value>1</value><email>praveen@imean.local</email><id>100001</id><first_name>sue</first_name><last_name>stappler</last_name><photo>images/teacher.png</photo><total_students>2</total_students><student_list> <student> <id>200001</id> <first_name>john</first_name> <last_name>mathew</last_name> <photo>images/student.png</photo> </student> <student> <id>200002</id> <first_name>steve</first_name> <last_name>jobs</last_name> <photo>images/student.png</photo> </student></student_list><description_title>login success</description_title><description_message>correct username , password</description_message><session_id>ecaf065b3213179afcd0d9895691505c</session_id></command>
you can possibly check 2 states of request
- http response code
- check if data returned ´http 200 ok´
- data check
- deserialize response (simplexml, jackson json or fasterxml project)
- check deserialization status (if model changed or response empty, fail)
- match fields in deserialized object conditions
Comments
Post a Comment