1

I am using a Linux system for my personal usage. My internet provider had provided a login page, which will help to connect the internet. Once I login, then I am able to connect internet. But I need to login the internet for each and every time after system started.

Internally the login page had implemented the AJAX request to connect the server. I had figure-out the AJAX implementation code through browser developer console.

So, I am planning to write a simple Java code which should internally call the AJAX call and need to login the internet. So, once this code had implemented, I will write a shell script to call to execute the Java class, and I will make this shell script to executable at the time of system start-up.

So, is there any way to call/implement the AJAX call using JAVA standard edition code implementation? I am not asking for code. I am just asking is there any framework or Java method will available to do this one?

Below JavaScript code which I had identified using the FireBug.

function makeAjaxRequest(e, d, a, c) { 
    var b = getAjaxObject();
    b.open(e, a, true);
    b.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    b.send(d);
    b.onreadystatechange = getReadyStateHandler(b, c);
    addOverlay()
}

function checkSubmit() {
    if (status != 'LIVE') {
        document.frmHTTPClientLogin.mode.value = 191;
        if (validateLogin()) {
            UserValue = replaceAll(document.frmHTTPClientLogin.username.value, '\'', '\'\'');
            queryString = 'mode=191&username=' + encodeURIComponent(UserValue) + '&password=' + encodeURIComponent(document.frmHTTPClientLogin.password.value) + '&a=' + (new Date) .getTime() + producttype;
            if (loginstate != null) {
                queryString += '&state=' + loginstate
            }
            url = 'login.xml';
            makeAjaxRequest('POST', queryString, url, loginResponse)
        }
    } else {
        if (document.forms[0].btnSubmit.value == logoutValue) {
            document.frmHTTPClientLogin.mode.value = 193;
            queryString = 'mode=193&username=' + encodeURIComponent(document.frmHTTPClientLogin.username.value) + '&a=' + (new Date) .getTime() + producttype;
            url = 'logout.xml';
            makeAjaxRequest('POST', queryString, url, logoutResponse)
        }
    }
    return false
}
halfer
  • 18,701
  • 13
  • 79
  • 158
SRIHARIRAO M
  • 103
  • 1
  • 16
  • Create servlet which accepts request from client side javascript using ajax. – Ved Jul 09 '14 at 07:42
  • Hi @Ved, thanks for reply. But again to run the servlet i required a server. I need a process which will execute in standard alone system. – SRIHARIRAO M Jul 09 '14 at 08:49
  • Then you can directly call your providers jsp using ajax in javascript. (after making few changes). No need to put Java in between. – Ved Jul 09 '14 at 08:53
  • Dear @Ved, I am unable to understand your solution. Actually i do not know my provider implementation technology. I just found a ajax function in his script using FireBug. My plan is make the auto login at the time of my system startup. So, i will write a shell script which will be call at system startup. So, i that shell script, i will call a simple java class, in that java class i need to call the ajax function which is in javascript. So, is there any cross connecting from pure java to javascript or any alternative procedure which will help to resolve this issue. – SRIHARIRAO M Jul 09 '14 at 09:31
  • If you can get the values of `queryString` and `url` you can simply POST the request (`queryString`) to the URL (`url`) and have yourself logged in to your ISP account. There is no need of anything else, and it will probably work as long as your ISP doesn't require more sophistication like a valid user agent or fetching the log-in page first (which can also be done in Java). [Check this question.](http://stackoverflow.com/questions/1359689) In any case, post your code. Also check [this tutorial](http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/). – ADTC Jul 09 '14 at 10:15

0 Answers0