I'm trying to access a url from java (using java post method). The url is a login page. I then insert values (username and password) to it an try to post that page. Below is my code,
Expand|Select|Wrap|Line Numbers
- PrintWriter out = new PrintWriter(new FileWriter("GSA Report Log.txt"));
- String ipAddress = "******"; //give the ipadress here
- int portNo = 8000; //give the port number here
- String path = ""; //give the path(url)
- String data = ""; //give the inpurt parameters
- URL url = null;
- URLConnection conn = null;
- OutputStreamWriter wr = null;
- BufferedReader rd = null;
- StringBuffer sbTopKeywords = new StringBuffer();
- ArrayList list_TopKeywords = new ArrayList();
- //Process 1 - Login to the Appliance
- //The Requested URL : https://ipAddress:portNo/EnterpriseController?actionType=reload&lastcmd=login
- System.out.println("******************** Start of Porcess 1 ********************");
- path = "/EnterpriseController";
- data = "userName=" + URLEncoder.encode("******", "UTF-8") +
- "&password=" + URLEncoder.encode("****", "UTF-8");
- url = new URL("http://" + ipAddress +":"+ portNo + path);
- conn = url.openConnection();
- conn.setDoOutput(true);
- wr = new OutputStreamWriter(conn.getOutputStream());
- wr.write(data);
- System.out.println(data);
- System.out.println(wr.toString());
- wr.flush();
- rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = rd.readLine()) != null) {
- System.out.println(line);
- }
- System.out.println("******************** End of Porcess 1 ********************");
- wr.close();
- rd.close();
Expand|Select|Wrap|Line Numbers
- Access to this system requires that you allow cookies to be set on your computer. Please enable cookies in your
- browser and hit reload twice. You can find your cookie settings under "Tool
- s -> Internet Options" for Internet Explorer and "Edit -> Preferences&
- quot; for Netscape.
Expand|Select|Wrap|Line Numbers
- while ((line = rd.readLine()) != null) {
- System.out.println(line);
- }
Any thoughts on this please do share. Thanks a lot :)
fREDDIE