Получение Cookies по HttpWebRequest - C#
Формулировка задачи:
Решил я написать программу которая обменивает пароль и логин на кукисы,
но они почему то не приходят, хотя я полностью дублировал post запрос с снифера.
В ответ должны приходить куки "l=idчеловека" и "p=непонятныйхеш"
Но самое главное это строка для пере адресации:
"Location: http://vk.com/login.php?act=slogin&al_frame=1&hash=буковкиициферки&s=1"
Попытался сделать запрос такого типа:
Всё равно не кукисов, не Location
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
namespace FastDoorSaw
{
public partial class Form1 : Form
{
public HttpWebRequest request;
public HttpWebResponse response;
public string SomeText_2;
public byte[] byteArray;
public Stream netStream;
public string SomeText;
public Form1()
{
InitializeComponent();
}
private string GetCook(string getmail, string getpass, string gethost)
{
string remixcook = "fail =(";
try
{
request = (HttpWebRequest)WebRequest.Create(new Uri("http://" + gethost));
request.AllowAutoRedirect = false;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; ru) Opera 8.50";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Method = "GET";
request.CookieContainer = new CookieContainer();
response = (HttpWebResponse)request.GetResponse();
SomeText = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("windows-1251")).ReadToEnd();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
request = (HttpWebRequest)WebRequest.Create(new Uri("https://login." + gethost + ":443/?act=login"));
SomeText_2 = "act=login&q=1&al_frame=1&expire=&captcha_sid=&captcha_key=&from_host=" + gethost + "&ip_h=" + SomeText.Substring(SomeText.IndexOf("ip_h: '") + 7, 18) + "&email=" + getmail + "&pass=" + getpass;
request.Headers.Add("DNT", "1");
request.Headers.Add("Accept-Encoding", "gzip, deflate");
request.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
request.Method = "POST";
request.Referer = "http://" + gethost + "/al_index.php?act=auth_frame";
byteArray = Encoding.UTF8.GetBytes(SomeText_2);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
request.AllowAutoRedirect = true;
response = (HttpWebResponse)request.GetResponse();
SomeText = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("windows-1251")).ReadToEnd();
foreach (Cookie c in response.Cookies)
{
remixcook += "\r\n" + c.Name + " " + c.Value;
}
}
catch (Exception lol)
{
MessageBox.Show(lol + "");
}
return remixcook;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(GetCook("моёмыло%40gmail.com", "пароль", "vk.com"));
}
}
}request = (HttpWebRequest)WebRequest.Create(new Uri("http://" + gethost + "/login.php?act=login&q=1&al_frame=1&expire=&captcha_sid=&captcha_key=&from_host=" + gethost + "&ip_h=" + SomeText.Substring(SomeText.IndexOf("ip_h: '") + 7, 18) + "&email=" + getmail + "&pass=" + getpass));
request.Method = "POST"; //GET тоже побывал
request.AllowAutoRedirect = true;
response = (HttpWebResponse)request.GetResponse();
remixcook += "\r\n" + response.GetResponseHeader("Location");
foreach (Cookie c in response.Cookies)
{
remixcook += "\r\n" + c.Name + " " + c.Value;
}Решение задачи: «Получение Cookies по HttpWebRequest»
textual
Листинг программы
captcha_sid=&captcha_key=