using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
namespace WebApplication1
{
public partial class WebForm16 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//string result = OpenReadWithHttpsWithLogin("https://mail.10086.cn/Login/Login.ashx", "UserName=用户名&Password=密码&SavePwd+=0&clientid=6002");
string result = OpenReadWithHttpsWithLogin("https://mail.10086.cn/Login/Login.ashx?_fv=5&cguid=1355493160018&_=9df8092ff53dbe8dc0df5015f6e7b22e60f2f295", "UserName=用户名&Password=密码&VerifyCode=");
Response.Write(result);
}
///<summary>
///采用https协议访问网络
///</summary>
///<param name="URL">url地址</param>
///<param name="strPostdata">发送的数据</param>
///<returns></returns>
public static string OpenReadWithHttpsWithLogin(string URL, string strPostdata)
{
Encoding encoding = Encoding.Default;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "post";
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/x-www-form-urlencoded";
CookieContainer objcok = new CookieContainer();
request.CookieContainer = objcok;
byte[] buffer = encoding.GetBytes(strPostdata);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));
LoginInfo.LoginCookie = objcok;
return reader.ReadToEnd();
}
public static class LoginInfo
{
/// <summary>
/// 登录后得到的令牌
/// </summary>
public static string Token { get; set; }
/// <summary>
/// 登录后得到的cookie
/// </summary>
public static CookieContainer LoginCookie { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public static DateTime CreateDate { get; set; }
}
}
}
模拟登陆139邮箱
最新推荐文章于 2024-01-31 17:26:01 发布