Get data from a website in android -
i developed app in windows phone 8/8.1, trying develop android users. getting data website , displaying in app. website needs login userid,password. implemented in c#. unable in java. can guide me.
my code in c# :
httpclienthandler handler = new httpclienthandler(); httpclient client = new httpclient(handler, false); handler.allowautoredirect = true; handler.preauthenticate = true; uri vceuri = new uri("http://xxxx/default.aspx"); var html = await client.getstringasync(siteuri); var doc = new htmlagilitypack.htmldocument(); doc.loadhtml(html); var viewstatenode = doc.getelementbyid("__viewstate"); var eventvalidationnode = doc.getelementbyid("__eventvalidation"); var viewstate = viewstatenode.getattributevalue("value", ""); var eventvalidation = eventvalidationnode.getattributevalue("value", ""); var formcontent1 = new formurlencodedcontent(new[] { new keyvaluepair<string, string>("__viewstate", viewstate), new keyvaluepair<string, string>("__eventvalidation", eventvalidation), new keyvaluepair<string,string>("txtloginid",_username), new keyvaluepair<string,string>("txtpwd",_pswd), new keyvaluepair<string,string>("btnlogin","go%21") }); var outputdoc = await client.postasync("http://xxx/default.aspx", formcontent1); html = await outputdoc.content.readasstringasync(); doc.loadhtml(html); // parsing(doc); var studentinfonode = doc.getelementbyid("divstudinfo"); var _studentinfonode1 = studentinfonode.childnodes; var studentinfo = studentinfonode.childnodes[0].childnodes;
the above studentinfo object contain required data
i tried using httpclient + httppost ending in null exception :(
if ever worked on similar application can please me.
thanks
Comments
Post a Comment