Oppure

Loading
14/08/10 7:55
francescobigozzi
Come da titolo devo far premere un bottone alla mia applicazione.
Senza naturalmente far intergire con l'utente.
So che bisogna usare la clesse WebRequest.
Grazie a coloro che risponderanno.
aaa
14/08/10 9:42
Il Totem
Dipende di che pulsante si tratta. Se è un <input> di tipo "submit", allora premerlo significa inviare il form a cui appartiene, e si può fare con una HttpWebRequest, inviando tutti i dati del form. Se è un <input> di tipo "button", allora avrà probabilmente qualche javascript allegato, e inviare una richiesta con WebRequest non servirebbe a nulla, poiché gli script sono lato client. In quest'ultimo caso, dovresti ottenere la struttura di tutta la pagina in un HtmlDocument, e scorrere tutti gli elementi fino al pulsante, quindi invocarne il click tramite HtmlElement.Invoke:
totemslair.org/guide/…
totemslair.org/guide/…
aaa
14/08/10 12:07
francescobigozzi
Grazie. Dimenticavo che devo anche scrivere una stringa in una casella di testo.

<input type="text" name="url" class="input" id="url" />
Qui devo scrivere un URL.

<input type="submit" name="submit" value="Button" class="button" />
E qui premere il bottone.

Mi pare di capire che il bottone è di tipo submit.
Adesso mi leggo la tua guida.
aaa
14/08/10 18:31
francescobigozzi
Non sono riuscito a risolvere molto per la verità :(

Devo realizzare un applicazione che scrive su una pagina php una stringa e prema un bottone.

Per semplicità posto il codice.

            //Scive sulla stringa response il codice HTML della pagina web
            response = CodeHTML("http://www.video2mp3.net/index.php");
            if (response.Contains("<input type=\"text\" name=\"url\" class=\"input\" id=\"url\" />") && response.Contains("<input type=\"submit\" name=\"submit\" value=\"Convert\" class=\"button\" />"))
                MessageBox.Show("La textbox e il bottone esistono!");          
        }

        private string CodeHTML(string url)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            using (Stream stream = request.GetResponse().GetResponseStream())
            using (StreamReader reader = new StreamReader(stream))
                return response = reader.ReadToEnd();
        }


Riesco solo a verificare l'esistenza del bottone e della textbox, ma non sono ancora riuscito a capire come scriverci!!
Ultima modifica effettuata da francescobigozzi 15/08/10 7:36
aaa
15/08/10 9:52
francescobigozzi
Ho trovato un codice in rete, ma non so se ho capito come usarlo.

public static string HttpPost(string URI, string Parameters)
{
   System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
   req.Proxy = new System.Net.WebProxy(ProxyString, true);
   //Add these, as we're doing a POST
   req.ContentType = "application/x-www-form-urlencoded";
   req.Method = "POST";
   //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value&
   byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
   req.ContentLength = bytes.Length;
   System.IO.Stream os = req.GetRequestStream ();
   os.Write (bytes, 0, bytes.Length); //Push it out there
   os.Close ();
   System.Net.WebResponse resp = req.GetResponse();
   if (resp== null) return null;
   System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
   return sr.ReadToEnd().Trim();
}
aaa
15/08/10 9:58
Il Totem
Forse è meglio che comprendi prima come funziona un form:
xhtml.html.it/guide/lezione/1696/struttura-del-tag-form/
aaa
15/08/10 10:45
francescobigozzi
Compreso.

Ricapitoliamo:
Nella pagina in cui devo interagire vengono usati dei javascipt, quindi per inserire del testo dovrei mandargli dei parametri e, siccome non compaiono nell'url e viene usato il metodo POST, il codice che avevo postato dovrebbe andar bene.
A questo punto come deve essere impostata la stringa Parameters?

Grazie per avermi prestato attenzione.
Ultima modifica effettuata da francescobigozzi 15/08/10 10:48
aaa
16/08/10 8:43
Il Totem
Postato originariamente da francescobigozzi:

Compreso.

Ricapitoliamo:
Nella pagina in cui devo interagire vengono usati dei javascipt, quindi per inserire del testo dovrei mandargli dei parametri e, siccome non compaiono nell'url e viene usato il metodo POST, il codice che avevo postato dovrebbe andar bene.
A questo punto come deve essere impostata la stringa Parameters?

Grazie per avermi prestato attenzione.


La query che devi inviare è esattamente identica a una query GET ("param=value&param1=value2...";), solo che viene scritta sullo stream di rete.
aaa