private string GET(string Url)
{
var reqGet = WebRequest.Create(Url);
var resp = reqGet.GetResponse();
var stream = resp.GetResponseStream();
var sr = new StreamReader(stream);
var Out = sr.ReadToEnd();
sr.Close();
return Out;
}
private string POST(string Url, string Data)
{
ServicePointManager.Expect100Continue = false;
var cookies = new CookieContainer();
var reqPost = (HttpWebRequest) WebRequest.Create(Url);
reqPost.CookieContainer = cookies;
reqPost.Method = "POST";
reqPost.Timeout = 100000;
reqPost.ContentType = "application/x-www-form-urlencoded";
byte[] sentData = Encoding.UTF8.GetBytes(Data);
reqPost.ContentLength = sentData.Length;
var sendStream = reqPost.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
using (var responseStream = reqPost.GetResponse().GetResponseStream())
using (var reader = new StreamReader(responseStream))
{
string Out = reader.ReadToEnd();
return Out;
}
}
private void http_auth_vk(string login, string pass)
{
//*****************************
//Получаем action_url
//*****************************
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
string Out = GET("http://m.vk.com/");
//*****************************
//Парсим
//*****************************
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(Out);
var bodyNode = doc.DocumentNode.SelectSingleNode("//div[@class='form_item fi_fat']/form");
var _result = bodyNode.Attributes["action"].Value;
//*****************************
//POST запрос
//*****************************
string data = "email=" + login + "&pass=" + pass;
Out = POST(_result, data);
//*****************************
//Парсим, поиск ID
//*****************************
doc.LoadHtml(Out);
try
{
bodyNode = doc.DocumentNode.SelectSingleNode("//h2[@class='op_header']/a");
labelUserInfo.Text = bodyNode.InnerText + " - ";
bodyNode = doc.DocumentNode.SelectSingleNode("//div[@class='ip_user_link']/a");
labelUserInfo.Text += "ID " + bodyNode.Attributes["href"].Value.Substring(3);
bodyNode = doc.DocumentNode.SelectSingleNode("//div[@class='ip_user_link']/a/img");
userImg.Load(bodyNode.Attributes["src"].Value);
bodyNode = doc.DocumentNode.SelectSingleNode("//ul[@class='left_footer_menu']/li[4]/a");
_logOut = bodyNode.Attributes["href"].Value;
//Если ID найден, то авторизация удалась
LoadGroup();
}
catch
{
//Если ID не найден, то авторизация не удалась
MessageBox.Show("Авторизация не удалась. Возможно там капча=(");
this.buttonCnct.Enabled = true;
this._login.Enabled = true;
this._pass.Enabled = true;
}
}
private void LoadGroup()
{
string Out = ;
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(Out);
HtmlNodeCollection nodes =
doc.DocumentNode.SelectNodes("//div[@id='gr_search_items']/a[@class='simple_fit_item']");
foreach (var node in nodes)
{
}
}