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 8240037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:21:01+00:00 2026-06-07T20:21:01+00:00

So there is this website that has a login form. I want to log

  • 0

So there is this website that has a login form. I want to log in and then download a file. When submitting the form, not only do username and password get transmitted in the http POST but also a token that is in a hidden <input> tag.
Now, my Problem is that whenever I open the URL in java and get the token to make a POST the token is invalid when I use a HttpClient.
I somehow need to use the same client for calling the website to get the token and making the post. Unfortunately I get a 403 FORBIDDEN return code when trying to access the file.
This is what I have so far:

public static void main(String[] args){



    try {
        String token = getTokenFromPage("http://my.url");   

        HttpContext context = new BasicHttpContext();   
        DefaultHttpClient client = new DefaultHttpClient();         

        List <NameValuePair> parameters = new ArrayList <NameValuePair>();
        HttpPost post = new HttpPost("http://my.url");
        parameters.add(new BasicNameValuePair("username", "MYNAME"));
        parameters.add(new BasicNameValuePair("password", "MYPW"));
        parameters.add(new BasicNameValuePair("token", token));

        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, HTTP.UTF_8);
        post.setEntity(entity); 

        System.out.println("URL: " + post.getURI());
        HttpResponse postResponse = client.execute(post, context);
        System.out.println(postResponse.getStatusLine());
        EntityUtils.consume(postResponse.getEntity());
//Now download the file

        HttpGet httpget = new HttpGet("http://url.to.file");

        HttpResponse getResponse = client.execute(httpget, context);

        System.out.println(getResponse.toString());

        System.out.print((postResponse.getEntity().getContent()));
        client.getConnectionManager().shutdown();


    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
  • 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-07T20:21:02+00:00Added an answer on June 7, 2026 at 8:21 pm

    You are going to have to make an HTTP request for the login page, parse the resulting HTML in the HTTP response stream, and get the token value to use from there. Using a library like jsoup to parse the HTML would be advisable.

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

Sidebar

Related Questions

I just want to design this very simple website. Basically there are multiple pages
I am building a mobile website, In this a form is there but no
I request a website header, however, there is not Last-Modified info in this http
I am trying to create a login form on my ASP.NET website. Currently, there's
I have a spring form that is used to log in to the website.
In this website there are a list of for loop variations. I can understand
I've recently come across this website. Now, is there any way I can actually
In my website there is a link like this http://backlinks.cheapratedomain.com/backlinks.php?url=emobileload.com for better SEO I
There is a website in Joomla, the NavigationPath ist domain.tld/index.php/produkte/produkt1.html this work fine. But
Is this fine or is there a different way? <a href=Http://<%=Html.Encode(Model.Website)%>><%=Html.Encode(Model.Website??)%></a>

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.