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.


3838 posts

Uber Geek
+1 received by user: 468

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/OpenHAB: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,OpenHAB with Aeotech ZWave Controller
Media:Chromecast v2, ATV4, Roku3, Raspberry PI temperature Sensors and Bluetooth LE Sensors,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
3137 posts

Uber Geek
+1 received by user: 877

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.

6314 posts

Uber Geek
+1 received by user: 380

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.



3838 posts

Uber Geek
+1 received by user: 468

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/OpenHAB: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,OpenHAB with Aeotech ZWave Controller
Media:Chromecast v2, ATV4, Roku3, Raspberry PI temperature Sensors and Bluetooth LE Sensors,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



3838 posts

Uber Geek
+1 received by user: 468

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/OpenHAB: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,OpenHAB with Aeotech ZWave Controller
Media:Chromecast v2, ATV4, Roku3, Raspberry PI temperature Sensors and Bluetooth LE Sensors,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:





News »

IBM leads Call for Code to use cloud, data, AI, blockchain for natural disaster relief
Posted 25-May-2018 14:12


New FUJIFILM X-T100 aims to do better job than smartphones
Posted 24-May-2018 20:17


Stuff takes 100% ownership of Stuff Fibre
Posted 24-May-2018 19:41


Exhibition to showcase digital artwork from across the globe
Posted 23-May-2018 16:44


Auckland tops list of most vulnerable cities in a zombie apocalypse
Posted 23-May-2018 12:52


ASB first bank in New Zealand to step out with Garmin Pay
Posted 23-May-2018 00:10


Umbrellar becomes Microsoft Cloud Solution Provider
Posted 22-May-2018 15:43


Three New Zealand projects shortlisted in IDC Asia Pacific Smart Cities Awards
Posted 22-May-2018 15:14


UpStarters - the New Zealand tech and innovation story
Posted 21-May-2018 09:55


Lightbox updates platform with new streaming options
Posted 17-May-2018 13:09


Norton Core router launches with high-performance, IoT security in New Zealand
Posted 16-May-2018 02:00


D-Link ANZ launches new 4G LTE Dual SIM M2M VPN Router
Posted 15-May-2018 19:30


New Panasonic LUMIX FT7 ideal for outdoor: waterproof, dustproof
Posted 15-May-2018 19:17


Ryanair Goes All-In on AWS
Posted 15-May-2018 19:14


Te Papa and EQC Minecraft Mod shakes up earthquake education
Posted 15-May-2018 19:12



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.