Facebookのキャプチャ画像をC#で取得してから、アプリに表示して、応答をFacebookに送信しようとしています。私のアプリは基本的にFacebookと通信しますが、しばらくするとキャプチャを要求します。キャプチャを入力する機能を組み込みました。webclient を使用して Facebook に送信すると、応答で別のキャプチャが検出されます。TemperData inn Firefox で再確認しましたが、正しいヘッダー情報とすべてのフィールドを設定していますが、それでも正しいページにリダイレクトされません。実際のところ、応答ヘッダーでは、TemperData と比較して 1 つのフィールドが欠落していることがわかります。
req = (HttpWebRequest)WebRequest.Create("https://www.facebook.com/recover/initiate");
req.Host = "www.facebook.com";
req.CookieContainer = cookies;
req.Method = "GET";
req.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefenter code hereox/22.0";
req.KeepAlive = true;
resp = req.GetResponse();
streamReader = new StreamReader(resp.GetResponseStream());
s = streamReader.ReadToEnd().Trim();
index = s.IndexOf("https://www.facebook.com/captcha/tfbimage.php?");
if (index == -1)
continue;
string uri = s.Substring(index);
uri = uri.Substring(0, uri.IndexOf("\\\"") - 1);
string captcha_persist_data = s.Substring(s.IndexOf("captcha_persist_data"));
captcha_persist_data = captcha_persist_data.Substring(captcha_persist_data.IndexOf("value") + 7);
captcha_persist_data = captcha_persist_data.Substring(0, 1156);
string lsd = s.Substring(s.IndexOf("lsd"));
lsd = lsd.Substring(lsd.IndexOf("value") + 7);
lsd = lsd.Substring(0, 8);
client = new WebClient();
coo += "act=1375466977443%2F3;_e_0p4M_2=%5B%220p4M%22%2C1375466960620%2C%22act%22%2C1375466960619%2C2%2C%22captcha_response%22%2C%22click%22%2C%22click%22%2C%22-%22%2C%22r%22%2C%22%2Frecover%2Finitiate%22%2C%7B%22ft%22%3A%7B%7D%2C%22gt%22%3A%7B%7D%7D%2C0%2C0%2C0%2C1423%2C16%5D;wd=1920x796;_e_0p4M_3=%5B%220p4M%22%2C1375466977445%2C%22act%22%2C1375466977443%2C3%2C%22captcha_submit%22%2C%22click%22%2C%22click%22%2C%22-%22%2C%22r%22%2C%22%2Frecover%2Finitiate%22%2C%7B%22ft%22%3A%7B%7D%2C%22gt%22%3A%7B%7D%7D%2C0%2C0%2C0%2C1423%2C16%5D";
client.Headers[HttpRequestHeader.Host] = "www.facebook.com";
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0";
client.Headers[HttpRequestHeader.Accept] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
client.Headers[HttpRequestHeader.AcceptLanguage] = "en-US,en;q=0.5";
//client.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
client.Headers[HttpRequestHeader.Referer]="https://www.facebook.com/recover/initiate";
client.Headers[HttpRequestHeader.Cookie] = coo;
//client.Headers[HttpRequestHeader.Connection] = "keep-alive";
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
//client.Headers[HttpRequestHeader.ContentLength] = "1235";
image1.Source = new BitmapImage(new Uri(uri));
MessageBox.Show("Alert");
streamReader = new StreamReader("D:\\abc.txt");
string newStr = streamReader.ReadLine();
streamReader.Close();
nameValuePairs = new NameValueCollection();
nameValuePairs.Add("lsd", lsd);
nameValuePairs.Add("captcha_persist_data", captcha_persist_data);
nameValuePairs.Add("captcha_response", newStr);
nameValuePairs.Add("captcha_submit", "Submit");
response = client.UploadValues("https://www.facebook.com/recover/initiate", nameValuePairs);
chars = new char[response.Length];
for (int i = 0; i < response.Length; i++)
{
chars[i] = Convert.ToChar(response[i]);
}
s = new string(chars);
どんな助けでも大歓迎です。