[C#] 纯文本查看 复制代码 public class _12306api
{
HttpHelper http = new HttpHelper();
HttpItem item = null;
string cookie = "";
public Image getcodeimg()
{
http = new HttpHelper();
item = new HttpItem()
{
URL = "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand",//URL 必需项
Method = "get",//URL 可选项 默认为Get
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
ResultType = ResultType.Byte
};
HttpResult result = http.GetHtml(item);
cookie = result.Cookie;
Image code=byteArrayToImage(result.ResultByte);
return code;
}
private Image byteArrayToImage(byte[] Bytes)
{
MemoryStream ms = new MemoryStream(Bytes);
Image outputImg = Image.FromStream(ms);
return outputImg;
}
public string Login(string user,string pwd,string randcode)
{
http = new HttpHelper();
item = new HttpItem()
{
URL = "https://kyfw.12306.cn/otn/login/loginAysnSuggest?loginUserDTO.user_name=" + user + "&userDTO.password=" + pwd + "&randCode=" + randcode + "",//URL 必需项
Method = "get",//URL 可选项 默认为Get
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = cookie,
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
};
HttpResult result = http.GetHtml(item);
string html = result.Html;
return html;
} |