POST login into a website. java-android

I'm trying to login into a website using java and jsoup. But every time I execute my post request I get an IOExeption. The website is www.seriecanal.com. I would appreciate it if someone could review the html form and tell me if I am creating the name-value pairs correctly and if there are any other obvious mistakes with the login. Here's my code:

public HttpResponse postData() 
{
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://seriecanal.com/index.php?page=member");

    try 
    {

        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);


        //Get value of input "Regresa_web" because it changes each time i access the site
        String Codigo_Fuente ="";
        URL url = new URL("http://seriecanal.com/");
        URLConnection conn = url.openConnection();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line = "";
        while ((line = rd.readLine()) != null) 
        {
            Codigo_Fuente= Codigo_Fuente+line;
        }
        Document Doc = Jsoup.parse(Codigo_Fuente);
        Element Regresa_WEb = Doc.getElementById("regresa_web");
        String Valor_Regresa_Web = Regresa_WEb.attr("value");


        //create name value pairs of the form
        nameValuePairs.add(new BasicNameValuePair("_UserName", "userontheweb"));
        nameValuePairs.add(new BasicNameValuePair("_Pwd", "123456789"));
        nameValuePairs.add(new BasicNameValuePair("btnLogin", "Ingresar"));
        nameValuePairs.add(new BasicNameValuePair("_submit_check", "1"));
        nameValuePairs.add(new BasicNameValuePair("remember", "ON"));
        nameValuePairs.add(new BasicNameValuePair("regresa_web", Valor_Regresa_Web));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse Response = httpclient.execute(httppost);
        return Response;

    } 
    catch (ClientProtocolException e) 
    {           
        return null;
    } 
    catch (IOException e) 
    {       
        Log.i("ERROR", e.toString());
        e.printStackTrace();
        return null;
    }
}

Stack:

04-21 13:42:04.206: D/dalvikvm(324): GC freed 15163 objects / 721152 bytes in 153ms
04-21 13:42:08.026: I/Resources(324): Loaded time zone names for en_US in 1863ms.
04-21 13:42:23.816: I/global(324): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
04-21 13:42:25.696: D/dalvikvm(324): GC freed 21866 objects / 1346160 bytes in 168ms

Answers


If you use fiddler or firebug you can interrogate the actual parameters that get sent. When I did this this is what I saw

_submit_check=1

btnLogin=Ingresar

password=test

remember=ON

username=test

It looks like you are sending the wrong params. The form input names do seem different to the ones being sent e.g. _UserName, but you never know if javascript is bound to the event and there is some additional magic going on there. As a result i always use firebug/fiddler.


Need Your Help

oracle-sqldeveloper mouse mapping issue

mapping mouse oracle-sqldeveloper

I found several articles describing the same issue i have, but didn't find a solution.

Moq.MockRepository.Of() usage when method has void return

c# unit-testing moq

I am using Moq's MockRepository.Of&lt;> method to mock various methods to test. When I chain multiple methods setups together via the Where clause it works when the mocked methods have a return. Th...