235 messaggi dal 27 aprile 2009
ciao a tutti, allora è da un po' che ci provo ma non riesco a farlo funzionare vediamo se voi mi potete aiutare.

Ho un pagina su un sito web all'indirizzo
http://199.199.99.99/cgi-bin/download.cgi.
All'interno di questa pagina c'è un form:

<html>
<head>
</head>
<body>
<form action="http://199.199.99.99/cgi-bin/download.csv" method="post" id="frmDownload" >

<h3>Tipo di dati:</h3><input type="radio" name="aggregate" value="" > Dati grezzi<br>

<input type="radio" name="aggregate" value="day"> Risultato giornaliero<br>
<input type="radio" name="aggregate" value="week" checked="" > Risultato settimanale<br>
<input type="radio" name="aggregate" value="month" > Risultato mensile<br>
<input type="radio" name="aggregate" value="year"> Risulato annuale<br><br><h3>Inizio del periodo:</h3>

<table width="100%">
<tbody>
<tr>
  <td width="50">Data:</td>
  <td><input type="text" name="start_day" value="01.01.2011"></td>
</tr>
<tr>
<td>Ora:</td>
  <td><input type="text" name="start_time" value="00:00"></td>
</tr>
</tbody>
</table>

<br><h3>Fine del periodo:</h3>

<table width="100%">
<tbody>
<tr>
  <td width="50">Data:</td><td><input type="text" name="end_day" value="31.01.2012"></td>
</tr>
<tr>
  <td>Ora:</td><td><input type="text" name="end_time" value="00:00"></td>
</tr>
</tbody>
</table>
<input type='submit' value='Scarica il file'>
</form>

</body>
</html>



Mettiamo che mi faccio una pagina HTML con dentro quel codice e lo eseguo tutto funziona.

Io vorrei creare batch exe console Windows, dove mando in post quella pagina cosi che mi scarica il file.

provato a fare cosi


                StringBuilder valueData = new StringBuilder(100);
                valueData.Append("radio=");
                valueData.Append("'week'");
                valueData.Append("&start_day=");
                valueData.Append("'01.01.2012'");
                valueData.Append("&start_time=");
                valueData.Append("'00:00'");
                valueData.Append("&end_day=");
                valueData.Append("'31.01.2012'");
                valueData.Append("&end_time=");
                valueData.Append("'00:00'");

                // Create a request using a URL that can receive a post. 
                WebRequest request = WebRequest.Create("http://199.199.99.99/cgi-bin/download.cgi");

                // Set the Method property of the request to POST.
                request.Method = "POST";

                // Create POST data and convert it to a byte array.
                string postData = valueData.ToString();

                byte[] byteArray = Encoding.UTF8.GetBytes(postData);

                // Set the ContentType property of the WebRequest.
                request.ContentType = "multipart/form-data";

                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;

                // Get the request stream.
                Stream dataStream = request.GetRequestStream();

                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);

                // Close the Stream object.
                dataStream.Close();

                // Get the response.
                WebResponse response = request.GetResponse();

                // Display the status.
                Console.WriteLine(((HttpWebResponse)response).StatusDescription);

                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();
               
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
             
                // Read the content.
                string responseFromServer = reader.ReadToEnd();

                // Display the content.
                Console.WriteLine(responseFromServer);

                // Clean up the streams.
                reader.Close();
                dataStream.Close();
                response.Close();

                Console.ReadLine();



Ma non funziona.
:(
Modificato da Stefano_VR il 31 gennaio 2012 10.29 -
Stefano_VR wrote:
Ma non funziona.

cioè? va in errore? sicuro che arrivi la chiamata? btw, con la classe Webclient hai un comodo metodo DownloadData, che è molto più semplice di usare direttamente HttpWebRequest.
.

Daniele Bochicchio | ASPItalia.com
I libri su HTML5, WP7, ASP.NET, VB, C#, Entity Framework
Senior Software Architect@5DLabs.it
Microsoft Regional Director for Italy

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.
Community
Ultimi messaggi
UTENTI ONLINE
In primo piano

I più letti di oggi

Media
In evidenza
MISC