人々に感謝します...私はあなたの答えを調査しましたが、はい、うまくいきました...いくつかの有効な資格情報でFacebookにログインできます...それは素晴らしい!!! :) 以下は私の最終的なコードです:-
CookieCollection cookies = new CookieCollection();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://www.facebook.com");
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
//Get the response from the server and save the cookies from the first request..
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies;
string getUrl = "https://www.facebook.com/login.php?login_attempt=1";
string postData = String.Format("email={0}&pass={1}", "", "");
HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
getRequest.CookieContainer = new CookieContainer();
getRequest.CookieContainer.Add(cookies); //recover cookies First request
getRequest.Method = WebRequestMethods.Http.Post;
getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
getRequest.AllowWriteStreamBuffering = true;
getRequest.ProtocolVersion = HttpVersion.Version11;
getRequest.AllowAutoRedirect = true;
getRequest.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
getRequest.ContentLength = byteArray.Length;
Stream newStream = getRequest.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
{
string sourceCode = sr.ReadToEnd();
ViewBag.Message = sourceCode;
}
もちろん、コードには httpwebrequest と httpwebresponse 以外にも多くのものが含まれています
...ログイン時に取得する必要があるもの...
2)(これは私の以前の質問に対する答えです。つまり、URLが機能しているかどうかを確認する方法です)したがって、ページのコンテンツを文字列(この場合はsourceCode)で取得し、次にあなたが考える特定の文字列を検索します結果のページにある可能性があります...この場合のように、ログインに成功すると、FBのユーザーのホームページにリダイレクトされる可能性があります。そのページには、ユーザー名やページタイトルなどのものが含まれる可能性があります「Facebook」など...nなど...資格情報の有無にかかわらずURLの成功をどのように確認するか....
それだけです...その簡単なことに、ほぼ3日かかりました...!!! ばかげている!