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.


3983 posts

Uber Geek
+1 received by user: 513

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

Uber Geek
+1 received by user: 890

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.

6319 posts

Uber Geek
+1 received by user: 382

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.



3983 posts

Uber Geek
+1 received by user: 513

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



3983 posts

Uber Geek
+1 received by user: 513

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 »

Intel introduces new NUC kits and NUC mini PCs
Posted 16-Aug-2018 11:03


The Warehouse leaps into the AI future with Google
Posted 15-Aug-2018 17:56


Targus set sights on enterprise and consumer growth in New Zealand
Posted 13-Aug-2018 13:47


Huawei to distribute nova 3i in New Zealand
Posted 9-Aug-2018 16:23


Home robot Vector to be available in New Zealand stores
Posted 9-Aug-2018 14:47


Panasonic announces new 2018 OLED TV line up
Posted 7-Aug-2018 16:38


Kordia completes first live 4K TV broadcast
Posted 1-Aug-2018 13:00


Schools get safer and smarter internet with Managed Network Upgrade
Posted 30-Jul-2018 20:01


DNC wants a safer .nz in the coming year
Posted 26-Jul-2018 16:08


Auldhouse becomes an AWS Authorised Training Delivery Partner in New Zealand
Posted 26-Jul-2018 15:55


Rakuten Kobo launches Kobo Clara HD entry level reader
Posted 26-Jul-2018 15:44


Kiwi team reaches semi-finals at the Microsoft Imagine Cup
Posted 26-Jul-2018 15:38


KidsCan App to Help Kiwi Children in Need
Posted 26-Jul-2018 15:32


FUJIFILM announces new high-performance lenses
Posted 24-Jul-2018 14:57


New FUJIFILM XF10 introduces square mode for Instagram sharing
Posted 24-Jul-2018 14:44



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.