0

I need to log in to a website with Java, its an https(SSL) site. I have some code that doesn't give me an error but it doesn't log in. I've tried a similar program in python and it didnt login either. I think I'm missing some basic concept about this... What am I doing wrong?

package zangle;

import java.io.*;
import java.net.*;

public class Zangle {

    public static void main(String[] args) {
        try {
            // Construct data
            String data = URLEncoder.encode("stuident", "UTF-8") + "=" + URLEncoder.encode("username", "UTF-8");
            data += "&" + URLEncoder.encode("stupassword", "UTF-8") + "=" + URLEncoder.encode("password", "UTF-8");

            // Send data
            URL url = new URL("https://webconnect.bloomfield.org/Zangle/StudentConnect/logincheck.aspx");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();

            // Get the response
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
            wr.close();
            rd.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by gsingh2011
0

make sure that you are connected to the server

It displays the entire html of the page, so I know it connected. The problem is it shows the html of the login page, not the page after it logged in.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.