0

I'm trying to access an internal site project, This is the a part of the page source for the site

<form method="post" action="doDelete">
     Are you sure you want to delete 'Apple?'?
 <input name="Submit" value="Yes" class="submit-button" type="submit" />
 </form>

I have this code

doSubmit("http://ma.some-website:8080/member/Apple/delete","Yes");

 public static void doSubmit(String url, String data) throws Exception {
    String content = "";
    URL siteUrl = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) siteUrl.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    conn.setDoInput(true);
    HttpURLConnection.setFollowRedirects( true );
    DataOutputStream out = new DataOutputStream(conn.getOutputStream());

        content =  URLEncoder.encode(data, "UTF-8");

    System.out.println(content);
    out.writeBytes(content);
    out.flush();
    out.close();
    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line = "";
    while((line=in.readLine())!=null) {
        System.out.println(line);
    }
    in.close();

}

In the webpage there is a confirmation box asking if "i wish to delete this user(Apple)" how do i programmatically click that? I'm thinking i need to identify the method which is "doDelete" and pass in "Yes" parameter?

kaiz.net
  • 1,984
  • 3
  • 23
  • 31
shinra tensei
  • 693
  • 5
  • 20
  • 39

1 Answers1

0

Your question is slightly confusing. You seem to be trying to simulate a browser by making http calls. I would recommend using a proxy of some sort to record the http calls you want to reproduce, then you can code them up as required. Might be worth googling for a framework to make this easier.

davidfrancis
  • 3,734
  • 2
  • 24
  • 21
  • Sorry meant that as a comment doh daft iPhone posting – davidfrancis Mar 05 '12 at 23:35
  • 1
    Alright i had to do HTMLUNIT to accomplish this. Works now. Here is the link if you guys are interested http://stackoverflow.com/questions/9589802/htmlunit-getformbyname-with-no-form-name-specified-in-the-website – shinra tensei Mar 06 '12 at 20:28