我想创建一个批处理脚本来自动登录aspx页面,该怎么做?
这是我的脚本代码:
@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
但这不行..
默认情况下,单击处理程序由 ASP.Net 调用(它们依赖于 ViewState),除非对代码进行更改,否则无法从外部调用。
如果您可以修改abctest.aspx中的代码,那么可以通过处理POST来完成。下面粘贴了一个粗略的例子:
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");
//
}