Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


4099 posts

Uber Geek
+1 received by user: 544

Trusted

Topic # 150931 8-Aug-2014 08:44
Send private message

It's one area I'm not very good at, is working out the query strings and post data for logging into sites programmatically.

I do use TUC for a usage tracking app I have at home (like to corroborate it will gargoyles reported usage) - with the the spark change that's broken.  I know he'll fix it, but I'd like to remove my reliance on it, and deal with it myself.

Also have asked many times for an API, and basically told no.

So what I've worked out is there should be a request to:
https://www.spark.co.nz/portal/site/digital-site/template.PAGE/action.process/menuitem.354c3e0302b1aa1994910bf3bc407ea0/?javax.portlet.action=true&javax.portlet.tpst=b85a693813b5760362a127b4bc407ea0&javax.portlet.begCacheTok=com.vignette.cachetoken&javax.portlet.endCacheTok=com.vignette.cachetoken

With the post data of:

loginSrc=ext
username=<email address>
password=<password>

and what seems to be a new key of:
sign-in=Sign In (which encoded is Sign+In)

But whenever I get the response back it always seems to be back to the sign in page.  And I can't see an error reported in the html/


So here's the code:
System.Net.WebRequest req = System.Net.WebRequest.Create(mURL);
req.Method = "POST";
byte[] send = System.Text.Encoding.Default.GetBytes("loginSrc=ext&username=<encoded email address>&password=<password>&sign-in=Sign+In");
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = send.Length;
req.Proxy = System.Net.WebRequest.DefaultWebProxy;

System.IO.Stream sout = req.GetRequestStream();
sout.Write(send, 0, send.Length);
sout.Flush();
sout.Close();

System.Net.WebResponse res = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(res.GetResponseStream());
lcHtml = sr.ReadToEnd();



Any help appreciated.






Previously known as psycik

NextPVR: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,
OpenHAB: ODroid C2 eMMC DriveOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 2012 
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Create new topic
3211 posts

Uber Geek
+1 received by user: 918

Trusted

  Reply # 1104825 8-Aug-2014 12:27
Send private message

You might need to include cookies from the original page.  Give this a try, in a console app with HtmlAgilityPack and Json.net nuget packages installed:

https://gist.github.com/anonymous/d62d564370ba7523787a

It works for me to do something like what I assume you're trying to, giving an output like:

Used 15.4580920003355 of 30 GB for period 21/07/2014 - 20/08/2014

It's pretty hacky code but hopefully it gives the idea.

6328 posts

Uber Geek
+1 received by user: 391

Moderator
Trusted
Lifetime subscriber

  Reply # 1104835 8-Aug-2014 12:49
Send private message

Abit snowed under the moment, but pseudo code would be:

1. Hit this page (https://www.spark.co.nz/portal/site/digital-site/template.PAGE/signin/) and get the action part of the form
2. Post back the five different form values - username, password, redirectUrl, emailValidationToken, showSignInAsDifferentUser AND all the cookies as well (there's 16 of them in total)

Try and replicate the real page interactions exactly and it should work fine.



4099 posts

Uber Geek
+1 received by user: 544

Trusted

  Reply # 1104890 8-Aug-2014 14:19
Send private message

sidefx: You might need to include cookies from the original page.  Give this a try, in a console app with HtmlAgilityPack and Json.net nuget packages installed:

https://gist.github.com/anonymous/d62d564370ba7523787a

It works for me to do something like what I assume you're trying to, giving an output like:

Used 15.4580920003355 of 30 GB for period 21/07/2014 - 20/08/2014

It's pretty hacky code but hopefully it gives the idea.


Awesome.  I need to clean up what I've got, but I've managed to get a number out.  

I think the main bit might have been holding the cookies as you and Nate pointed out.

The page that I'm getting to is different than I've seen before (seems to almost be a data dump which is nice).

But I'll clean it up.  Thanks so much.





Previously known as psycik

NextPVR: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,
OpenHAB: ODroid C2 eMMC DriveOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 2012 
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


11 posts

Geek
Inactive user


  Reply # 1105969 10-Aug-2014 17:33
Send private message

I'm having the same problems here. No help for their service desk. undecided



4099 posts

Uber Geek
+1 received by user: 544

Trusted

  Reply # 1106001 10-Aug-2014 19:11
Send private message

manly100: I'm having the same problems here. No help for their service desk. undecided


The same problems how? With an app that scrapes their site? No, they don't help you with that.




Previously known as psycik

NextPVR: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,
OpenHAB: ODroid C2 eMMC DriveOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 2012 
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Create new topic

Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.