Hello,
i want to simulate a web browser.
After connected of the site, i make the login.
After login I have a cookie :
/* output Wireshark sniffing */
[truncated] Cookie: CAD=30658829%231240647532%234444%230%23itx%237251; TTQ_OPTIONS=LAST_REFRESH,1240703848087,SCOUT_UNIT,4,RACE,1,FORM_POSITION,216px_148px,MSG_POSITION,214px_212px,LIST_POSITION,-68px_766px; T3E=%3DUjM4MDM3ADNyEjO1ADOyAzNw
/* SEE "[truncated]" */
example of code :
try
{
URL travian = new URL("http://example.it/login.php");
URLConnection connection = travian.openConnection();
BufferedReader read = new BufferedReader(new InputStreamReader(connection.getInputStream()));
connection.connect();
String inputline;
while((inputline = read.readLine()) != null)
{
html += inputline + "\n";
}
CercaString(); // search a pair of name-value fields to login
URL myUrl2;
myUrl2 = new java.net.URL("http://example.it/dorf1.php");
java.net.URLConnection urlConn2 = myUrl2.openConnection();
urlConn2.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(urlConn2.getOutputStream());
out.write(post);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConn2.getInputStream()));
String decodedString;
while ((decodedString = in.readLine()) != null)
{
System.out.println(decodedString);
}
in.close();
// This is a test!
String temp = "";
for(int i=0; i < 16; i++)
{
temp+= "\n"+urlConn2.getHeaderField(i);
}
System.out.println("STAMPO:\n" + temp);
Setcookie = urlConn2.getHeaderField("Set-cookie");
System.out.println(Setcookie);
}
catch(Exception e)
{
e.printStackTrace();
}
...
...
...
other code
...
...
...
try
{
java.net.URL Url1 = new java.net.URL("http:/example.it/build.php?id=2");
java.net.URLConnection connection1 = Url1.openConnection();
BufferedReader read = new BufferedReader(new InputStreamReader(connection1.getInputStream()));
connection1.setRequestProperty("Set-Cookie", Setcookie);
connection1.connect();
String inputline;
while((inputline = read.readLine()) != null)
{
html += inputline + "\n";
}
System.out.println(html); //Da cancellare
}
catch(Exception e)
{
e.printStackTrace();
}
OTUPUT:
HTTP/1.1 200 OK
nginx
Sun, 26 Apr 2009 00:09:24 GMT
text/html; charset=UTF-8
chunked
keep-alive
PHP/5.2.6
T3E=%3D%3DAN3AjNxoDN2UDNwcDM0ITM6YjOkVWNyMmNjBTNzojezwWdSpTM1IzN6AzIwMSM1IzN; expires=Mon, 26-Apr-2010 00:09:24 GMT; path=/; httponly
Mon, 26 Jul 1997 05:00:00 GMT
Sun, 26 Apr 2009 00:09:24 GMT
no-store, no-cache, must-revalidate
post-check=0, pre-check=0
no-cache
null
null
null
T3E=%3D%3DAN3AjNxoDN2UDNwcDM0ITM6YjOkVWNyMmNjBTNzojezwWdSpTM1IzN6AzIwMSM1IzN; expires=Mon, 26-Apr-2010 00:09:24 GMT; path=/; httponly
java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(Unknown Source)
at Prova.ampliaGrano(Prova.java:231)
at Test.main(Test.java:11)
please help me because i haven't understand very good ..
(please explain with teory and example)
Thanks!