FAQ  •  Register  •  Login

Site Login's

<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Sun Mar 04, 2012 4:29 pm

Site Login's

I have a groovy which requires a site login to get an extended set of links.
Here is the login page http://www.ilive.to/login
Any suggestions on how to program this in a groovy?
I note the NHLgamecenter groovy seems to use httpbuilder to do this.
I don't know if User-agent can be used in this way.
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Tue Mar 06, 2012 7:46 pm

Re: Site Login's

Anyone???
<<

smmortazavi

Serviio newbie

Posts: 4

Joined: Mon Feb 20, 2012 9:45 am

Post Sat Apr 21, 2012 4:25 am

Re: Site Login's

I have done this in one groovy before and I share it here hoping it helps.
use login() method bellow first and after a successful login include login cookie ("PHPSESSID=$loginCookie") in all subsequent requests:

  Code:
    def String login() {
     def url = "http://www.ilive.to/login"
     def userName="myuser"
     def paswd="mypass"
     
     String loginCookie = getCookie(url,"PHPSESSID");
     String loginResult = doPOST(url, "username=$userName&password=$paswd", "PHPSESSID=$loginCookie")
     return loginResult

     //If login is successfull make all other subsequent requests with the above cookie ("PHPSESSID=$loginCookie") to get the extended channel list
    }

    def String getCookie(String _url, String cookieName) throws Exception{
        def headerName, rv = "Not Found";       
        // creeating the url connection object
        URL url = new URL(_url)
        URLConnection urlConnection = url.openConnection();
       
        // checking for each headers
        for (int i=1; (headerName = urlConnection.getHeaderFieldKey(i))!=null; i++) {
            // if its set-cookie, then take it
            if (headerName.equalsIgnoreCase("Set-Cookie")) {                 
                String cookie = urlConnection.getHeaderField(i);
                String cName = cookie.split("=")[0];
                String cValue = cookie.split("=")[1];
                if (cName.equalsIgnoreCase(cookieName))
                 return cValue.replaceAll(";.*","")
            }
        }
        return rv;
    }
 
    def String doPOST(String _url, String data, String cookie) {
        // Construct data
        def rv = ""
        URL url = new URL(_url);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("Cookie", cookie);
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
   
        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {

            rv += line
        }
        wr.close();
        rd.close();       
    return rv
}

<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Sun May 13, 2012 5:54 pm

Re: Site Login's

I don't know how I missed your post, but thank you, its exactly what I was looking for. I'll try it and post back.

Return to Plugin development

Who is online

Users browsing this forum: No registered users and 18 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.