私はわずか数週間前にC#で遊び始めました。私は実行しようとしている作業をしているし、私は今それを行う方法が正しいアプローチであるかどうかを確認していません。ボタンをクリックしてウェブサイトにログインしようとしています
私は(より良いオプションの湖のための私の場合のWordPressウェブサイト - 中)のウェブサイトにログインしようとすると、C#を使用して管理パネルにナビゲートしています
これまでのところ、私は新しいプロジェクトを作成していた何をやったか - Windowsのフォームアプリケーション。
次のコード - 私は、その後にレスポンスのクッキーを取るために、このコードを持っているパスワード/ユーザ名とPOST
private void button2_Click(object sender, EventArgs e)
{
CookieContainer cookieJar = new CookieContainer();
CookieContainer cookieJar2 = new CookieContainer(); // will use this later
string testaa = ""; // will use this later
string paramaters = "log=xxxx&pwd=xxxx&testcookie=1&redirect_to=http://www.example.com/wp-admin/&wp-submit=Log In";
string strResponse;
HttpWebRequest requestLogin = (HttpWebRequest)WebRequest.Create("http://www.lyndatobin-howes.com/wp-login.php");
requestLogin.Method = "POST";
requestLogin.AllowAutoRedirect = false;
requestLogin.ContentType = "application/x-www-form-urlencoded";
requestLogin.CookieContainer = cookieJar;
requestLogin.ContentLength = paramaters.Length;
StreamWriter stOut = new StreamWriter(requestLogin.GetRequestStream(), Encoding.ASCII);
stOut.Write(paramaters);
stOut.Close();
}
などの他のパラメータとのウェブサイトにリクエストを送信します。
私はこれを読んで+いくつかのストリームを閉じます。
StreamReader stIn = new StreamReader(requestLogin.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
string responseFromServer = stIn.ReadToEnd();
webBrowser1.DocumentText = responseFromServer;
stIn.Close();
response.Close();
し、私は次のように、私がアクセスしようとしていますページの上のクッキーを使用してみてください:
HttpWebRequest requestLogin2 = (HttpWebRequest)WebRequest.Create("http://www.example.com/wp-admin/");
requestLogin2.Method = "POST";
requestLogin2.AllowAutoRedirect = false;
requestLogin2.ContentType = "application/x-www-form-urlencoded";
requestLogin2.CookieContainer = cookieJar2;
requestLogin2.ContentLength = paramaters.Length;
StreamWriter stOut2 = new StreamWriter(requestLogin2.GetRequestStream(), System.Text.Encoding.ASCII);
stOut2.Write(paramaters);
stOut2.Close();
StreamReader stIn2 = new StreamReader(requestLogin2.GetResponse().GetResponseStream());
strResponse = stIn2.ReadToEnd();
string responseFromServer2 = stIn2.ReadToEnd();
webBrowser1.DocumentText = responseFromServer2;
richTextBox2.Text += "\n\n\n" + responseFromServer2;
stIn.Close();
まあ、それは私がこれをしようとしてきたいくつかの理由で動作しません。今週。
最初にリクエストした後、どのヘッダーが返されたかを確認しようとしました。 (cookieJar2)を見て、それは同じではないようです。
とにかく、どんな助けも素晴らしいと非常に高く評価されます。私はできるだけ多くの詳細を与えるようにした。
私は応答のクッキーを取得し続けるだけで、私は他の4つのクッキーを紛失していると考えているからです。これで何をするべきかわかりません。 –
誰でも構いませんか? –
まだ問題をお探しですか? –