Questo topic e' stato chiuso dal moderatore.
25/08/14 15:10
Jie
Ciao a tutti, sto scrivendo un programma che si collega al sito web.spaggiari.eu/home/app/default/… e inserisce automaticamente quanto digitato nel textbox, simulando il passaggio del badge.
Finora ho scritto questo codice, che però non è in grado di dirmi se la sequenza digitata sia stata accettata o meno:
Qualcuno potrebbe illuminarmi?
Finora ho scritto questo codice, che però non è in grado di dirmi se la sequenza digitata sia stata accettata o meno:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Net; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private bool InfoSchoolAccess(string badge_ident) { CookieContainer cookies = new CookieContainer(); HttpWebRequest request = null; HttpWebResponse response = null; string returnData = string.Empty; //Need to retrieve cookies first request = (HttpWebRequest)WebRequest.Create(new Uri("https://web.spaggiari.eu/home/app/default/login.php?mode=badge")); request.Method = "GET"; request.CookieContainer = cookies; response = (HttpWebResponse)request.GetResponse(); //Set up the request request = (HttpWebRequest)WebRequest.Create(new Uri("https://web.spaggiari.eu/home/app/default/login.php?mode=badge")); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"; request.Referer = "https://web.spaggiari.eu/home/app/default/login.php?&mode=badge"; request.AllowAutoRedirect = true; request.KeepAlive = true; request.CookieContainer = cookies; //Format the POST data StringBuilder postData = new StringBuilder(); postData.Append(String.Format("badge_ident={0}", badge_ident)); //write the POST data to the stream using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) writer.Write(postData.ToString()); response = (HttpWebResponse)request.GetResponse(); //Read the web page (HTML) that we retrieve after sending the request using (StreamReader reader = new StreamReader(response.GetResponseStream())) returnData = reader.ReadToEnd(); richTextBox1.AppendText(returnData); return !returnData.Contains("Errore"); } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { InfoSchoolAccess(textBox1.Text); } private void richTextBox1_TextChanged(object sender, EventArgs e) { } } }
Qualcuno potrebbe illuminarmi?
Ultima modifica effettuata da Jie 25/08/14 15:12
aaa