how to create a batch script to automatic aspx page login?

47 Views Asked by At

I want to create a batch script to automatic login aspx page, how to do it ?

this is my script code:

@echo off

REM Set variables
set "url=http://abctest.aspx"
set "username=test
set "password=pass"

REM Send POST request to login
curl -d "username=%username%&password=%password%" -X POST %url% -o response.html

REM Display the response
type response.html

but it is not work ..

1

There are 1 best solutions below

0
Sekhar On

By default, the click handlers are invoked by ASP.Net (they depend on ViewState), and cannot be called externally unless changes are made to the code.

If you can modify the code within abctest.aspx, then it can be done by handling the POST. A rough example pasted below:

protected void Page_Load(object sender, EventArgs e)
{
    //Treat curl's POST method, but ignore the regular POST, as it will be handled by ASP.NET
    if (Request.HttpMethod == "POST" & !IsPostBack)
    {
        username.Text = Request["username"];
        password.Text = Request["password"];
        btnLogin_Click(this, null);
    }
}

protected void btnLogin_Click(object sender, EventArgs e)
{
    Response.Write("Success");
    //
}