|
[code=csharp]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DotNet.Utilities;
using System.Text.RegularExpressions;
namespace PP2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string cookie = "";
private void button1_Click(object sender, EventArgs e)
{
string url1 = "https://www.paypal.com/c2/cgi-bin/webscr?cmd=_login-run";
HttpResult resout = GetHttpResult(url1, "Get","","");
textBox3.Text = GetRegex(resout.Html, @"input name=""auth"" type=""hidden"" value=""(.+?)""><input ",1);
string emailInfo = textBox1.Text;
string password = textBox2.Text;
string url = "https://www.paypal.com/c2/cgi-bin/webscr?cmd=_login-submit";
string postData = "login_cmd=&login_params=&login_email=" + textBox1.Text + "&login_password=" + textBox2.Text + "&target_page=0&submit.x=%E7%99%BB%E5%BD%95&auth=" + textBox3.Text + "&form_charset=UTF-8&browser_name=MSIE&browser_version=9&browser_version_full=9.0&operating_system=Windows";
HttpResult result = GetHttpResult(url, "Post", "", postData);
cookie = result.Cookie;
textBox4.Text = cookie;
richTextBox1.Text = result.Html;
url = "https://www.paypal.com/c2/cgi-bin/webscr?cmd=_profile-summary&nav=0.4";
HttpResult result1 = GetHttpResult(url, "Get", cookie, "");
//richTextBox1.Text = result.Html;
}
private static HttpResult GetHttpResult(string url, string method, string cookie, string postData)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = url,//URL 必需项
Method = method,//URL 可选项 默认为Get
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = cookie,//字符串Cookie 可选项
Referer = "",//来源URL 可选项
Postdata = postData,//Post数据 可选项GET时不需要写
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
ContentType = "text/html",//返回类型 可选项有默认值
Allowautoredirect = true,//是否根据301跳转 可选项
//CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数
//Connectionlimit = 1024,//最大连接数 可选项 默认为1024
ProxyIp = "",//代理服务器ID 可选项 不需要代理 时可以不设置这三个参数
//ProxyPwd = "123456",//代理服务器密码 可选项
//ProxyUserName = "administrator",//代理服务器账户名 可选项
};
HttpResult result = http.GetHtml(item);
//string html = result.Html;
//string cookie = result.Cookie;
return result;
}
/// <summary>
/// 单条数据正则获取
/// </summary>
/// <param name="code">源码</param>
/// <param name="ruler">正则表达式</param>
/// <param name="id">返回结果下标</param>
/// <returns>string</returns>
private static string GetRegex(string code, string ruler, int id)
{
string matchValue = "";
Regex r = new Regex(ruler, RegexOptions.Singleline);
Match m = r.Match(code);
if (m.Success)
{
matchValue = m.Groups[id].ToString();
}
return matchValue;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
[/code]
|
|