1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Java login on vBulletim forum

Discussion in 'Other Languages' started by 0biwan, Apr 20, 2009.

  1. 0biwan

    0biwan Newbie

    Joined:
    Apr 15, 2009
    Messages:
    40
    Likes Received:
    15
    Hi, I'm trying to developed an app in java(to work on all SO's) to get all usernames names from vbulletim forums but some of them require to login to view the members page.

    I'm not being able to do that can someone help to see what's wrong in my code?

    Code:
    public class login {
        
        public void login(){}
        
        public void connect (String webp, String user, String pass) throws Exception{
    
        URL url = new URL(webp);
        String POST_CONTENT_TYPE = "application/x-www-form-urlencoded";
    
    // Open a HTTP connection to the URL
    
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    
    // Allow Inputs
    conn.setDoInput(true);
    
    // Allow Outputs
    conn.setDoOutput(true);
    
    // Don't use a cached copy.
    conn.setUseCaches(false);
    
    // Use a post method.
    conn.setRequestMethod("POST");
    
    conn.setRequestProperty("Connection", "Keep-Alive");
    conn.setRequestProperty("Authorization", "Basic" );
    conn.setRequestProperty("Content-Type", POST_CONTENT_TYPE);
    conn.setRequestProperty("Content-Type", "text/html; charset=iso-8859-1");
    conn.setFollowRedirects(true);
    conn.setInstanceFollowRedirects(true);
    
    
    
    
    DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
    
    StringBuffer content = new StringBuffer(1024);
    content.append("vb_login_username=" + URLEncoder.encode(user, "UTF-8"));
    content.append("vb_login_password=" +URLEncoder.encode(pass, "UTF-8"));
    
    dos.writeBytes(content.toString());
    System.out.println(conn.getPermission());
    
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String responeLine;
    
    // Good Practice: Use StringBuilder in this case
    StringBuilder response = new StringBuilder();
    
    // Read untill there is nothing left in the stream
    // throws IOException
    while ((responeLine = bufferedReader.readLine()) != null)
    {
    response.append(responeLine + "\n");
    }
    
    System.out.println (response.toString());
    
    dos.flush();
    dos.close();
        }
    
    }
    thanks
     
  2. heiska

    heiska Junior Member

    Joined:
    Dec 5, 2008
    Messages:
    138
    Likes Received:
    169
    I do realise that this thread is old, but in case anyone is having similar problems:
    You should first make a connection to the forum index in order to let the phpsessid etc cookies drop. Otherwise VB will bitch something about cookies not being enabled thus making it unable to log in.

    What's wrong with the code? I can't see you calling the connect void anywhere.. Also, l2indent please.