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.


3940 posts

Uber Geek
+1 received by user: 493

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
3157 posts

Uber Geek
+1 received by user: 887

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.



3940 posts

Uber Geek
+1 received by user: 493

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



3940 posts

Uber Geek
+1 received by user: 493

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 »

Microsoft Dynamics 365 Business Central launches
Posted 10-Jul-2018 10:40


Spark completes first milestone in voice platform upgrade
Posted 10-Jul-2018 09:36


Microsoft ices heated developers
Posted 6-Jul-2018 20:16


PB Technologies charged for its extended warranties and warned for bait advertising
Posted 3-Jul-2018 15:45


Almost 20,000 people claim credits from Spark
Posted 29-Jun-2018 10:40


Cove sells NZ's first insurance policy via chatbot
Posted 25-Jun-2018 10:04


N4L helping TAKA Trust bridge the digital divide for Lower Hutt students
Posted 18-Jun-2018 13:08


Winners Announced for 2018 CIO Awards
Posted 18-Jun-2018 13:03


Logitech Rally sets new standard for USB-connected video conference cameras
Posted 18-Jun-2018 09:27


Russell Stanners steps down as Vodafone NZ CEO
Posted 12-Jun-2018 09:13


Intergen recognised as 2018 Microsoft Country Partner of the Year for New Zealand
Posted 12-Jun-2018 08:00


Finalists Announced For Microsoft NZ Partner Awards
Posted 6-Jun-2018 15:12


Vocus Group and Vodafone announce joint venture to accelerate fibre innovation
Posted 5-Jun-2018 10:52


Kogan.com to launch Kogan Mobile in New Zealand
Posted 4-Jun-2018 14:34


Enable doubles fibre broadband speeds for its most popular wholesale service in Christchurch
Posted 2-Jun-2018 20:07



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.