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

  • Home
  • SEARCH
  • 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 7745491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:02:09+00:00 2026-06-01T10:02:09+00:00

This is my code: public static String sendPostRequest(String url) { StringBuffer sb = null;

  • 0

This is my code:

public static String sendPostRequest(String url) {

    StringBuffer sb = null;

    try {

        String data = URLEncoder.encode("user", "UTF-8") + "="
                + URLEncoder.encode("username", "UTF-8") + "&"
                + URLEncoder.encode("password", "UTF-8") + "="
                + URLEncoder.encode("password", "UTF-8");

        System.out.println(data); //Just to check if data is correct

        URL requestUrl = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) requestUrl
                .openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod("POST");

        DataOutputStream osw = new DataOutputStream(conn.getOutputStream());
        osw.writeBytes(data);
        osw.flush();

        BufferedReader br = new BufferedReader(new InputStreamReader(
                conn.getInputStream()));

        String in = "";
        sb = new StringBuffer();

        while ((in = br.readLine()) != null) {
            sb.append(in + "\n");
        }

        osw.close();
        br.close();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sb.toString();
}

But whenever I try to log in through this http post request, it returns the html code which is always on that page of the site, not my specific html code that contains my user page. The html login form looks like this:

 <td width="100" align="left"><span class="texte_listing_bold">Login:</span></td>
    <td width="300" align="center"><input class="form_size1" type="text" name="user"></td>
  </tr>
  <tr>
    <td width="100" align="left"><span class="texte_listing_bold">Password:</span></td>
    <td width="300" align="center"><input class="form_size1" type="password" name="password"></td>
  </tr>
  <tr>
    <td colspan="2" align="center">
        <input type="hidden" name="login_action" value="true">
        <input class="bouton_nosize" type="submit" value="Login">
    </td>

Normally, the buttons have the name elements, and I can call those as well through my code, which does work and lets me log into such a site, but this won’t work for some reason. What’s the reason for this?

  • 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-01T10:02:11+00:00Added an answer on June 1, 2026 at 10:02 am

    This login form uses a hidden input field called login_action with value true.

    You’ll need to pass that in your request along with username and password.

    Simply make sure you have provided all required information.
    You could check what the browser sends using a HTTP sniffer, but the best would be to look at the sources of the page you try to authenticate against.

    If you don’t have access or control over the web server login page source then you probably shouldn’t be writing this code in the first place. The authentication mechanism can change in the future, and there may be many security restrictions against scripts such as the one you are tring to write, since it’s generally not accepted to allow bots to login to user pages and web-scrape content.

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

Sidebar

Related Questions

I'm using this code: public static MjpegInputStream read(String url) { HttpResponse res; DefaultHttpClient httpclient
I have this code: public static DataTable ExecutesAMAccountNameQuery(string sAMAccountName) { string filter = (&(objectCategory=person)(objectClass=user)(sAMAccountName=
ok ive got this code: public static string ScreenScrape(string url) { System.Net.WebRequest request =
I run this code: public class User { public static void main(String args[]) {
Background I serialize a very large List<string> using this code: public static string SerializeObjectToXML<T>(T
Take a look at this code: public class Test { public static void main(String...
I'm using this code inside WPF application: public static string EncryptString(string stringToEncrypt) { SHA256
This is my code public static bool Login (string iduser, string password) { bool
I have this bit of code, public static List<string> GetSentencesFromWords(List<string> words, string fileContents) {
Say, I have a code snippet like this: public static void main(String[] args) {

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.