Mezzetti0903
10-05-2003, 22:10
Vi ricordate di me?? esatto sono quello della richiesta GET...bene quest'oggi i problemi sono con il POST.
In pratica vorrei inviare una richiesta POST ... con relativi dati...
ecco il codice che uso.. penso che sia abbastanza capibile sia per i Javari che per i C++ari....
string Post = "POST /test.asp HTTP/1.1\r\nHost: localhost"
+\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.0 [en]"
+"\r\nContent-Type: text/xml; charset=utf-8"
+"\r\n\r\nlogin=Alemagno"
+"&password=telemaco"
+"\r\n\r\n";
Byte[] ByteGet = Encoding.UTF8.GetBytes(Post);
String strRetPage = null;
// IPAddress and IPEndPoint represent the endpoint that will
// receive the request.
// Get the first IPAddress in the list using DNS.
IPAddress hostadd = Dns.Resolve(server).AddressList[0];
IPEndPoint EPhost = new IPEndPoint(hostadd, 80);
//Creates the Socket for sending data over TCP.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );
// Connects to the host using IPEndPoint.
s.Connect(EPhost);
// Sends the POST text to the host.
s.Send(ByteGet, ByteGet.Length, SocketFlags.None);
Come avrete capito...non funziona una mazza... quando provo a recuperare il valore dei parametri dalla pagina ASP mi da errore.
Dove sbaglio?? Nell'encoding, nella formulazione della richiesta o dove??
Ah un'ultima cosa... se dovessi usare nei valori la & o l'= dovrei convertirli in %NUM...vero?? Mi rivolgo ai .NETtiani.. come si chiama questa codifica?? c'è un modo per farla via .NET o la devo fare a mano??
Grazie in anticipo!
In pratica vorrei inviare una richiesta POST ... con relativi dati...
ecco il codice che uso.. penso che sia abbastanza capibile sia per i Javari che per i C++ari....
string Post = "POST /test.asp HTTP/1.1\r\nHost: localhost"
+\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.0 [en]"
+"\r\nContent-Type: text/xml; charset=utf-8"
+"\r\n\r\nlogin=Alemagno"
+"&password=telemaco"
+"\r\n\r\n";
Byte[] ByteGet = Encoding.UTF8.GetBytes(Post);
String strRetPage = null;
// IPAddress and IPEndPoint represent the endpoint that will
// receive the request.
// Get the first IPAddress in the list using DNS.
IPAddress hostadd = Dns.Resolve(server).AddressList[0];
IPEndPoint EPhost = new IPEndPoint(hostadd, 80);
//Creates the Socket for sending data over TCP.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );
// Connects to the host using IPEndPoint.
s.Connect(EPhost);
// Sends the POST text to the host.
s.Send(ByteGet, ByteGet.Length, SocketFlags.None);
Come avrete capito...non funziona una mazza... quando provo a recuperare il valore dei parametri dalla pagina ASP mi da errore.
Dove sbaglio?? Nell'encoding, nella formulazione della richiesta o dove??
Ah un'ultima cosa... se dovessi usare nei valori la & o l'= dovrei convertirli in %NUM...vero?? Mi rivolgo ai .NETtiani.. come si chiama questa codifica?? c'è un modo per farla via .NET o la devo fare a mano??
Grazie in anticipo!