Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8041653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:17:37+00:00 2026-06-05T04:17:37+00:00

I am writing the program in Java, and i want to fill out the

  • 0

I am writing the program in Java, and i want to fill out the specified fields of form, simulate submit clicking, so get the result page. I am testing my idea on the url http://stu21.kntu.ac.ir/Login.aspx that have two fields txtusername and txtpassword. I am trying the code as follow but it does not return the result page for me. How can i do it ? What do i wrong in this code ?

        DefaultHttpClient conn = new DefaultHttpClient();
        conn = new DefaultHttpClient();

        ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("txtusername", "8810103"));
        pairs.add(new BasicNameValuePair("txtpassword", "8810103"));

        HttpPost httpPost = new HttpPost("http://stu21.kntu.ac.ir/Login.aspx");
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs,
                "UTF-8");

        httpPost.setHeader(
                "UserAgent",
                "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/12.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19");

        httpPost.setEntity(entity);
        HttpResponse response = conn.execute(httpPost);
        InputStream is = response.getEntity().getContent();
        RandomAccessFile raf = new RandomAccessFile(
                "/home/hossein/Desktop/random.aspx", "rw");
        raf.seek(0);

        int bytes = 0;
        byte[] buffer = new byte[1024];

        while ((bytes = is.read(buffer)) != -1)
            raf.write(buffer, 0, bytes);

        raf.close();
        is.close();

Sorry if my question duplicates with another threads, i can not find my solution on other threads.

Thanks In Advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:17:39+00:00Added an answer on June 5, 2026 at 4:17 am

    I think you need HTTPUnit. There is a good tutorial at javaworld.

    Just look at the following example there :

    public void testGoodLogin() throws Exception {
        WebConversation     conversation = new WebConversation();
        WebRequest  request = new GetMethodWebRequest( "http://www.meterware.com/servlet/TopSecret" );
        WebResponse response = conversation.getResponse( request );
    
        WebForm loginForm = response.getForms()[0];
        request = loginForm.getRequest();
        request.setParameter( "name", "master" );
    
        // "clicking the button" programatically
        response = conversation.getResponse( request );
    
        assertTrue( "Login not accepted", 
                   response.getText().indexOf( "You made it!" ) != -1 );
        assertEquals( "Page title", "Top Secret", response.getTitle() );
    } 
    

    I am sure that you can do your testing just like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a java program that goes out and searches twitter, finds certain instagram
I'm writing a Java program that scrapes a web page for links and then
I'm writing a Java program, and I want a function that, given a string,
I'm writing a cross-platform program in Java and want to stick the configuration files
I'm writing a simple painting program using Java, and I want some method to
I'm writing a java program that works with .class files. I want to be
I'm writing a very simple program where I want to get user input from
I tried writing a program in Java using regex to match a pattern and
I'm writing a program in Java where I read in data from an XML
I am writing a program in java using sockets with UDP. For a number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.