Ho effettuato delle correzioni al codice, però continua non funzionare. Posto quest'ultimo, gli headers di richiesta, risposta e la stringa che viene inviata tramite post (risultato dello sniffing via browser)
codice:
import java.net.*;
import java.io.*;
import java.util.*;
class antefatto {
public static void main(String args[]) throws Exception{
String data=(new Date()).toString();
if(data.indexOf("Mon")>=0) {
System.out.println("Oggi e' lunedi' e il fatto quotidiano non esce");
return;
}
URL url;
HttpURLConnection connessione;
try{
url =new
URL("http://www.antefatto.it/servizi/login/login.aspx?redirect=%2fservizi%2futenti%2fprofilo.aspx");
connessione=(HttpURLConnection)url.openConnection();
connessione.setRequestMethod("POST");
connessione.setFollowRedirects(true);
connessione.setDoOutput(true);
}catch(MalformedURLException me){
System.out.println("Errore costruttore URL");
return;
}catch(IOException ie){
System.out.println("Errore openConnection");
return;
}
PrintWriter out;
try {
out=new PrintWriter(connessione.getOutputStream());
out.print(URLEncoder.encode("ScriptManager1=UpdatePanel1|Login1$LoginButton&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTY1MjA5MzAyOWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFEUxvZ2luMSRSZW1lbWJlck1lBRdMb2dpbjEkTG9naW5JbWFnZUJ1dHRvbjfjyH746ajNdVv6tHEQVjYewAqH&__EVENTVALIDATION=%2FwEWBQLihaedDwKUvNa1DwL666vYDAKC0q%2BkBgKnz4ybCC0CuWakl8o5oHUG8s8vvTlqZWRM&Login1$UserName=MiaEmail&Login1$Password=MiaPassword&Login1$LoginButton=Entra","UTF-8"));
}catch(IOException io){
System.out.println("Errore getOutputStream");
return;
}
BufferedReader in;
try{
in = new BufferedReader(new InputStreamReader (connessione.getInputStream()));
}catch(IOException ie){
System.out.println("Errore getInputStream");
return;
}
Map<String, List<String>> map =connessione.getHeaderFields();
Set<String> key=map.keySet();
List<String> cookie = map.get("Set-Cookie");
String line;
while ((line = in.readLine()) != null){
System.out.println(line);
}
for(String k : key){
System.out.println("Chiave: "+k+" Valore: "+map.get(k));
}
return;
}
}
(Request-Line) POST
/servizi/login/login.aspx?redirect=%2fservizi%2futenti%2fprofilo.aspx HTTP/1.1
Host www.antefatto.it
User-Agent Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.1.5) Gecko/20091109
Ubuntu/9.04 (jaunty) Shiretoko/3.5.5
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-MicrosoftAjax Delta=true
Cache-Control no-cache, no-cache
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Referer
http://www.antefatto.it/servizi/logi...i/profilo.aspx
Content-Length 432
Pragma no-cache
(Status-Line) HTTP/1.1 200 OK
Date Thu, 12 Nov 2009 10:29:37 GMT
Server Microsoft-IIS/6.0
X-powered-by ASP.NET
X-AspNet-Version 2.0.50727
Set-Cookie ASP.NET_SessionId=po5ftz45sh5r4z3ewvftyp45; path=/; HttpOnly
Cache-Control no-cache
Pragma no-cache
Expires -1
Content-Type text/plain; charset=utf-8
Content-Length 46
ScriptManager1=UpdatePanel1|Login1$LoginButton&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTY1MjA5MzAyOWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFEUxvZ2luMSRSZW1lbWJlck1lBRdMb2dpbjEkTG9naW5JbWFnZUJ1dHRvbjfjyH746ajNdVv6tHEQVjYewAqH&__EVENTVALIDATION=%2FwEWBQLihaedDwKUvNa1DwL666vYDAKC0q%2BkBgKnz4ybCC0CuWakl8o5oHUG8s8vvTlqZWRM&Login1$UserName=MiaEmail&Login1$Password=MiaPassord&Login1$LoginButton=Entra