0

我有一个 Java 类,我需要将用户名和密码传递给 URL 并检查登录是否成功。

这是Java类:

  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();
      }

   }

这是我在 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>

现在我要做的是为文本框用户名和密码赋值并提交表单。任何人都可以帮忙吗?

4

1 回答 1

0

您需要在表格中发布

username=xyz&password=abc
于 2013-09-11T10:26:44.020 回答