0

I have a Java class from which I need to pass username and password to an URL and check whether the login is succeeded or not.

Here is the Java Class:

  public void testIt(String username, String password){

      String https_url = "http://www.myurlgoeshere.com";
      URL url;
      try {

         url = new URL(https_url);
         HttpURLConnection con = (HttpURLConnection)url.openConnection();
         con.setDoOutput(true);
         con.setDoInput(true);
         OutputStreamWriter oStream = new OutputStreamWriter(con.getOutputStream());
         oStream.write("admin");
         InputStream in = con.getInputStream();

                System.out.println(in);
         //dumpl all cert info
         print_https_cert(con);

         //dump all the content
         print_content(con);

      } catch (MalformedURLException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }

   }

This is the form i have in the web URL:

<form id="javascript:void(0);" name="javascript:void(0);" onsubmit=" return fnOnSubmit();" action="javascript:void(0);" method="post">
<table class="wwFormTable">
                                                    <input type="hidden" name="userRole" value="" id="javascript:void(0);_userRole"/>                                       
                                                    <tr>
    <td class="tdLabel"><label for="javascript:void(0);_username" class="label">User Name :</label></td>
    <td
><input type="text" name="username" size="20" value="" id="javascript:void(0);_username" class="textbox" autocomplete="off"/></td>
</tr>

                                                    <tr>
    <td class="tdLabel"><label for="javascript:void(0);_password" class="label">Password :</label></td>
    <td
><input type="password" name="password" size="22" id="javascript:void(0);_password" class="textbox"/></td>
</tr>

                                                    <tr>
    <td colspan="2"><div align="right"><input type="submit" id="javascript:void(0);_label_login" name="method:execute" value="Login" class="groovybutton"/>
</div></td>
</tr>

                                                </table></form>

Now what i want to do is assign values to the textboxes username and password and submit the form. Can anyone help?

1 Answers1

0

You need to post in the form

username=xyz&password=abc
user207421
  • 289,834
  • 37
  • 266
  • 440