[ad_1]
を使用して Web サイトにログインしようとしています WebRequest
また WebClient
と、なかなかうまくいかないようです。
その理由の1つは、おそらく、その論理を十分に理解していないためです。
とにかく、これが私が現在使用しているコードです。 どんな助けでも大歓迎です。
C#
private void button2_Click(object sender, EventArgs e) { string URLAuth = "http://www.lyndatobin-howes.com/wp-login.php"; WebClient webClient = new WebClient(); NameValueCollection formData = new NameValueCollection(); formData["log"] = "xxxx"; formData["pwd"] = "xxxx"; formData["wp-submit"] = "Log In"; formData["redirect_to"] = "http://www.lyndatobin-howes.com/wp-login.php"; formData["testcookie"] = "1"; byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData); string resultAuthTicket = Encoding.UTF8.GetString(responseBytes); webClient.Dispose(); //string searchammount = comboBox1.SelectedItem.ToString(); WebRequest Logingrequest = WebRequest.Create("http://www.lyndatobin-howes.com/wp-login.php"); Logingrequest.Credentials = CredentialCache.DefaultCredentials; Logingrequest.ContentType = "application/x-www-form-urlencoded"; Logingrequest.Method = "POST"; WebResponse response = Logingrequest.GetResponse(); Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); richTextBox2.Text = responseFromServer; reader.Close(); dataStream.Close(); response.Close(); }
解決策 3
http://www.hanselman.com/blog/HTTPPOSTsAndHTTPGETsWithWebClientAndCAndFakingAPostBack.aspx[^]
またはこの方法を試してください..
C#
public static void PostString (string address) { string data = "Time = 12:00am temperature = 50"; string method = "POST"; WebClient client = new WebClient (); string reply = client.UploadString (address, method, data); Console.WriteLine (reply); }
または、このリンクを試してください。
解決策 1
別の方法を試しましたが、まだ何もありません:
どんな助けでも非常に高く評価されます。
C#
WebRequest Logingrequest = WebRequest.Create("http://www.lyndatobin-howes.com/wp-login.php"); Logingrequest.Credentials = CredentialCache.DefaultCredentials; Logingrequest.ContentType = "application/x-www-form-urlencoded"; Logingrequest.Method = "POST"; string postData = "log=admin&pwd=m7625zsw&wp-submit=Log In&redirect_to=http://www.lyndatobin-howes.com/wp-login.php&testcookie=1"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Set the ContentLength property of the WebRequest. Logingrequest.ContentLength = byteArray.Length; Stream dataStream = Logingrequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); WebResponse response = Logingrequest.GetResponse(); dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); richTextBox2.Text = responseFromServer; reader.Close(); dataStream.Close(); response.Close();
[ad_2]
コメント