|
You last visited: Today at 00:02
Advertisement
Facebook login Cookies Problem
Discussion on Facebook login Cookies Problem within the .NET Languages forum part of the Coders Den category.
11/03/2015, 16:33
|
#1
|
elite*gold: 0
Join Date: Aug 2010
Posts: 880
Received Thanks: 113
|
Facebook login Cookies Problem
Hi,
ich versuche mich bei Facebook einzuloggen mit Webrequest. Leider funktioniert das nicht und ich bekomme die meldung vom server, dass ich meine cookies im browser aktivieren muss.
Webrequest
Code:
static CookieCollection Cookies = new CookieCollection();
public static string pPost(string URL, string Post)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows; U; WIndows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";
request.CookieContainer = new CookieContainer();
foreach (Cookie entry in Cookies)
{
request.CookieContainer.Add(entry);
}
request.AllowAutoRedirect = true; //carefully with auto
// Wenn wir request sagen, das wir KEINEN proxy haben, sucht er keinen und die Anfrage geht um einiges schneller
request.Proxy = null;
// Post-Daten definieren und abschicken
string PostData = Post;
byte[] byteArray = Encoding.Default.GetBytes(PostData);
request.ContentLength = byteArray.Length;
Stream DataStream = request.GetRequestStream();
DataStream.Write(byteArray, 0, byteArray.Length);
DataStream.Close();
// Rückgabe holen
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
DataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(DataStream);
string ServerResponse = reader.ReadToEnd();
reader.Close();
DataStream.Close();
foreach (Cookie cook in response.Cookies)
{
Cookies.Add(cook);
}
response.Close();
return ServerResponse;
}
public static string WebRPost(string URL)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.UserAgent = "Mozilla/5.0 (Windows; U; WIndows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";
request.CookieContainer = new CookieContainer();
foreach (Cookie entry in Cookies)
{
request.CookieContainer.Add(entry);
}
request.AllowAutoRedirect = true; //carefully with auto
request.Proxy = null;
Stream DataStream = default(Stream);
// Rückgabe holen
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
DataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(DataStream);
string ServerResponse = reader.ReadToEnd();
foreach (Cookie cook in response.Cookies)
{
Cookies.Add(cook);
}
reader.Close();
DataStream.Close();
response.Close();
return ServerResponse;
}
Code:
string bla = Connection.pPost("https://www.facebook.com/login.php?login_attempt=1&lwv=110", "lsd=AVq8j7yX&email=***&pass=****&persistent=1&default_persistent=1&timezone=-60&lgndim=eyJ3IjoxOTIwLCJoIjoxMDgwLCJhdyI6MTkyMCwiYWgiOjEwNDAsImMiOjI0fQ%3D%3D&lgnrnd=050652_nFUt&lgnjs=1446206821&locale=de_DE&qsstamp=W1tbMTUsMzcsNjcsOTMsMTA1LDEwOSwxMjEsMTQ0LDE1MiwxNjcsMTc3LDE4MCwxOTIsMjAwLDIwFRrIl0%3D");
Die lsd und lgndim etc müssen ja vorher ausgelesen werden nicht wahr?
Jedoch funktioniert das auch nicht wenn ich die vorher auslese.
|
|
|
11/03/2015, 16:55
|
#2
|
elite*gold: 75
Join Date: Mar 2009
Posts: 528
Received Thanks: 21
|
I'm not fluent in German at all, but if I see correctly, you are creating new CookieContainer with each request, you should be reusing the same one to store cookies from a session.
|
|
|
11/04/2015, 15:08
|
#3
|
elite*gold: 0
Join Date: Aug 2010
Posts: 880
Received Thanks: 113
|
you mean like this?
Code:
static CookieCollection Cookies = new CookieCollection();
public static string pPost(string URL, string Post)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows; U; WIndows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";
//request.CookieContainer = new CookieContainer();
foreach (Cookie entry in Cookies)
{
request.CookieContainer.Add(entry);
Cookies.Add(entry);
}
request.AllowAutoRedirect = true; //carefully with auto
// Wenn wir request sagen, das wir KEINEN proxy haben, sucht er keinen und die Anfrage geht um einiges schneller
request.Proxy = null;
// Post-Daten definieren und abschicken
string PostData = Post;
byte[] byteArray = Encoding.Default.GetBytes(PostData);
request.ContentLength = byteArray.Length;
Stream DataStream = request.GetRequestStream();
DataStream.Write(byteArray, 0, byteArray.Length);
DataStream.Close();
// Rückgabe holen
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
DataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(DataStream);
string ServerResponse = reader.ReadToEnd();
reader.Close();
DataStream.Close();
foreach (Cookie cook in response.Cookies)
{
request.CookieContainer.Add(cook);
Cookies.Add(cook);
}
response.Close();
return ServerResponse;
}
public static string WebRPost(string URL)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.UserAgent = "Mozilla/5.0 (Windows; U; WIndows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";
//request.CookieContainer = new CookieContainer();
foreach (Cookie entry in Cookies)
{
Cookies.Add(entry);
request.CookieContainer.Add(entry);
}
request.AllowAutoRedirect = true; //carefully with auto
request.Proxy = null;
Stream DataStream = default(Stream);
// Rückgabe holen
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
DataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(DataStream);
string ServerResponse = reader.ReadToEnd();
foreach (Cookie cook in response.Cookies)
{
request.CookieContainer.Add(cook);
Cookies.Add(cook);
}
reader.Close();
DataStream.Close();
response.Close();
return ServerResponse;
}
|
|
|
11/04/2015, 16:06
|
#4
|
elite*gold: 75
Join Date: Mar 2009
Posts: 528
Received Thanks: 21
|
Quote:
Originally Posted by Ludder231
you mean like this?
Code:
static CookieCollection Cookies = new CookieCollection();
public static string pPost(string URL, string Post)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows; U; WIndows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";
request.CookieContainer = Cookies;
request.AllowAutoRedirect = true; //carefully with auto
// Wenn wir request sagen, das wir KEINEN proxy haben, sucht er keinen und die Anfrage geht um einiges schneller
request.Proxy = null;
// Post-Daten definieren und abschicken
string PostData = Post;
byte[] byteArray = Encoding.Default.GetBytes(PostData);
request.ContentLength = byteArray.Length;
Stream DataStream = request.GetRequestStream();
DataStream.Write(byteArray, 0, byteArray.Length);
DataStream.Close();
// Rückgabe holen
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
DataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(DataStream);
string ServerResponse = reader.ReadToEnd();
reader.Close();
DataStream.Close();
response.Close();
return ServerResponse;
}
public static string WebRPost(string URL)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.UserAgent = "Mozilla/5.0 (Windows; U; WIndows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";
request.AllowAutoRedirect = true; //carefully with auto
request.Proxy = null;
Stream DataStream = default(Stream);
// Rückgabe holen
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
DataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(DataStream);
string ServerResponse = reader.ReadToEnd();
request.CookieContainer = Cookies;
reader.Close();
DataStream.Close();
response.Close();
return ServerResponse;
}
|
I think more like this, it should do the trick just fine.
|
|
|
11/04/2015, 16:25
|
#5
|
elite*gold: 0
Join Date: Aug 2010
Posts: 880
Received Thanks: 113
|
i just checked out what cookies i get from the server. But i don't get any cookies from the server????
|
|
|
11/04/2015, 16:39
|
#6
|
elite*gold: 50
Join Date: Sep 2012
Posts: 3,841
Received Thanks: 1,462
|
|
|
|
11/04/2015, 17:32
|
#7
|
elite*gold: 273
Join Date: Sep 2010
Posts: 1,831
Received Thanks: 786
|
Erster link bei Google "c# httpwebrequest login":
|
|
|
11/06/2015, 04:32
|
#8
|
elite*gold: 100
Join Date: Aug 2005
Posts: 595
Received Thanks: 208
|
Quote:
|
request.AllowAutoRedirect = true; //carefully with auto
|
Der Kommentar hier ist wichtig und etwas ungenau 
WebRequest ist etwas Zickig wenns um Cookies geht, disable das mal und mach die Redirects selbst.
|
|
|
11/07/2015, 10:22
|
#9
|
elite*gold: 0
Join Date: Jan 2010
Posts: 990
Received Thanks: 127
|
Musst zuerst ein Request auf die Facebook startseite machen dannach auf den login post.
Ahja so wird das trotzdem nicht funktionieren, bei Facebook gibts einige Tokens die generiert werden (Dafür musst du das Javascript analysieren) und die musst du auch nachdem selben algorithmus generieren.
|
|
|
11/07/2015, 21:10
|
#10
|
elite*gold: 0
Join Date: Aug 2010
Posts: 880
Received Thanks: 113
|
Quote:
Originally Posted by DeinMud
Musst zuerst ein Request auf die Facebook startseite machen dannach auf den login post.
Ahja so wird das trotzdem nicht funktionieren, bei Facebook gibts einige Tokens die generiert werden (Dafür musst du das Javascript analysieren) und die musst du auch nachdem selben algorithmus generieren.
|
Hab die letzten Tage dran rumhantiert und bin zu dem selben Entschluss gekommen. Aber die tokens kann man sich ja über den Quelltext holen? lgrnd, lgnjs, qsstamp etc.
|
|
|
 |
Similar Threads
|
Facebook cookies sniffen (online auf dem iPhone ?)
06/30/2013 - Web Development - 3 Replies
Hallo epvp,
gestern hat ein Kollege von mir in meinem WLAN meine Cookies gesnifft von facebook und hat sich bei mir eingeloggt und irgendeine scheiße geschrieben.
Wie das auf dem PC geht ist mir klar mit Wireshark oder anderen programme, nur wie ich das ganze auf dem Handy mit irgendeiner Internetseite abfangen kann ist mir neu.
Könnte man sowas coden oder kennt jemand von euch so eine Seite ?
Kurze Geschichte von Ihm, "Ich musste mich auf einem Forum anmelden wo mein Freund mich...
|
[VB] Facebook login "Cookies erforderlich"
12/07/2012 - .NET Languages - 8 Replies
Hi,
ich wollte mich mit meinem Programm in Facebook einloggen aber facebook sagt, dass Cookies erfoderlich sind, obwohl ist diese requeste.
Private Function WebRPOST(ByVal Url As String, ByVal post As String, ByVal tempcookie As CookieContainer)
Dim Request As HttpWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)
Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
Request.UserAgent = " Mozilla/5.0 (Windows NT...
|
Facebook Likebox mit JavaScript Cookies
12/08/2011 - Web Development - 1 Replies
Hi, habe ein kleines Problem.
Würde gern folgenden Code in meiner Website einbauen, jedoch zeigt er mir nur eine weisse Seite. Im Quellcode steht aber auch das drin, was in der Datei steht.
Könnt ihr mir weiterhelfen?
|
Problem with bot development (Cookies)
01/26/2010 - General Coding - 7 Replies
Hey all, got a question for the other bot developers here.
Was trying to make a small bot for Grepolis (Building queue only).
I created my other bots with C#, using httpget and httppost requests. That way I can easily get the cookies from the response header (Set-Cookie).
But now comes the problem...
The developers of Grepolis found a way to set cookies without Set-Cookie. Looks like they use java script for it.
The cookie called PHPSESSID is still set using Set-Cookie but...
|
All times are GMT +1. The time now is 00:02.
|
|