I'm trying to use java (client application) to post an html request , the request perform a simple login task , the login variable is stored in the session , after the login the program is redirected to another page (default2) ,on load the default2 page check the session , but it finds it null! , help :omg: ( the Java isn't a web host , its a j2se program )
the web application is asp
try {
URL u = new URL("http://localhost:51132/WebSite5/Default.aspx?name=user&pass=password");
HttpURLConnection uc = (HttpURLConnection) u.openConnection( );
int code = uc.getResponseCode( );
String response = uc.getResponseMessage( );
System.out.println("HTTP/1.x " + code + " " +response);
for (int j = 1; ; j++) {
String header = uc.getHeaderField(j);
String key = uc.getHeaderFieldKey(j);
if (header == null || key == null) break;
System.out.println(uc.getHeaderFieldKey(j) + ": " +header);
}
InputStream in = new
BufferedInputStream(uc.getInputStream( ));
Reader r = new InputStreamReader(in);
int c;
while ((c = r.read( )) != -1) {
System.out.print((char) c);
}
}
catch (MalformedURLException ex) {
System.err.println(args[0] + " is not a parseable URL");
}
catch (IOException ex) {
System.err.println(ex);
}
}
the code of default.aspx which is the page i use for login
protected void Page_Load(object sender, EventArgs e)
{
string name = Page.Request.QueryString["name"];
string pass = Page.Request.QueryString["pass"];
if (name.CompareTo("user") == 0 && pass.CompareTo("password") == 0) {
Session["loged"]= "yes";
Response.Redirect("Default2.aspx");
}
}
the code of default2.aspx th page where i check the session variable
protected void Page_Load(object sender, EventArgs e)
{
if (Session["loged"] == null) {
Response.Redirect("error.aspx");
}
}