Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
ASP.NET 2.0 / 3.5 / 4.0
Richiesta form da C#
venerdì 18 luglio 2008 - 16.09
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
muccio04
Profilo
| Newbie
33
messaggi | Data Invio:
ven 18 lug 2008 - 16:09
ciao a tutti,
devo georeferenziare degli indirizzi, ossia data via, citta,provincia e n°civico, trovare la latitudine e la longitudine di tale indirizzo.
per fare cio pensavo di fare una web reqest a un sito ad esempio
http://www.tuttocitta.it/tcolnew/index_tcol.html
, ed inviargli i dati in mio possesso relativi all'indirizzo e di filtrare da query string i dati relativi alla longitudine e latitudine.
Qualcuno sa come posso effettuare una richiesta post a tale web server da codice C#, ossia come posso simulare il riempimento dei campi e l'invio della richiesta da codice C#?
grazie a tutti
Simone
rossimarko
Profilo
| Guru
1.173
messaggi | Data Invio:
ven 18 lug 2008 - 16:28
>Qualcuno sa come posso effettuare una richiesta post a tale web
>server da codice C#, ossia come posso simulare il riempimento
>dei campi e l'invio della richiesta da codice C#?
>grazie a tutti
>Simone
Ciao,
questo dovrebbe fare al caso tuo:
http://msdn.microsoft.com/en-us/library/debx8sh9.aspx
-----------------------------------------
Rossi Marco
http://blogs.dotnethell.it/rossimarko
muccio04
Profilo
| Newbie
33
messaggi | Data Invio:
ven 18 lug 2008 - 17:18
questo è il codice asp.net 2.0 che inserisco nella funzione page_load,
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("
http://www.tuttocitta.it/tcolnew/index_tcol.html"
);
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
//string postData = "This is a test that posts this string to a Web server.";
string postData = "cittaCT=Longiano&indirizzoCT=fratta&civicoCT=290";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// 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, questa riga da errore...proviamo con HttpRequest
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.
Response.Write(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
che mi riporta l'errore 405, sai dirmi qualcosa in merito?
rossimarko
Profilo
| Guru
1.173
messaggi | Data Invio:
lun 21 lug 2008 - 10:06
Purtroppo adesso non riesco a verificare, però ti posso dare il link a Fiddler, un tool che puoi utilizzare per vedere che richieste http vengono fatte dal sito quando effettui una ricerca:
http://www.fiddlertool.com/fiddler/
-----------------------------------------
Rossi Marco
http://blogs.dotnethell.it/rossimarko
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !