|
万能的站长,我这段时间一直在做一个CP面板的模拟登陆,登陆这一步可以登进去,但是登进去以后,抓取登陆后的个页面,却返回到登陆界面,一直在测试不成功,求万能的站长能不能帮忙解决一下,我感激不尽。
我的代码我就贴出来:
public Form1()
{
InitializeComponent();
}
private void btn_start_Click(object sender, EventArgs e)
{
//secure,whostmgrsession[\s\S]*?(2087);
string myhost =tb_url.Text;
HttpResult loginwhm = gethttp(myhost, "get");
string logincookie = loginwhm.Cookie;
HttpResult postwhm = gethttp(myhost + "/login/?login_only=1", "post", "user=root&pass=*******&goto_uri=%2F", logincookie);
string cookiec =regmatch("secure,whostmgrsession[\\s\\S]*?(2087);", postwhm.Cookie);
cookiec = cookiec + "timezone=Asia/Shanghai;path=/;port=2087;";
JsonParser jp = (JsonParser)JsonConvert.DeserializeObject<JsonParser>(postwhm.Html);
string gurl = myhost + jp.redirect;
HttpResult whmcon = gethttp(gurl, "get", "", cookiec);
tb_result.Text = whmcon.Html;
}
public HttpResult gethttp(string url,string method,string postdata="",string cookiec=""){
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = url,//URL 必需项
Method = method,//URL 可选项 默认为Get
Postdata = postdata,
CerPath = "D:\\mypro\\证书登陆\\cp.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数
ResultType = ResultType.Byte,
Cookie = cookiec
};
HttpResult result = http.GetHtml(item);
return result;
}
public string regmatch(string regs, string regcon)
{
Regex reg = new Regex(regs);
var mat = reg.Match(regcon);
if (mat.Length > 0)
{
return mat.Groups[0].ToString().Trim();
}
else
{
return "";
}
}
}
public class JsonParser
{
public int status;
public string security_token;
public string redirect;
}
因为这个是管理服务器的,所以地址,账号密码我就不公开了,我私信给站长,希望求解决。
|
|