hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Desholo <duccio.mag...@gmail.com>
Subject Retrieve HTML code after POST request
Date Wed, 09 Mar 2011 15:21:37 GMT

Hello everyone!
I'm new with HttpClient package so my question could be found silly, but I
searched a solution for some time with no answer.
I've to do an application that performs a POST request in a certain host,
then navigates some pages, finds and retrieves some data and waits for
instructions.
I've found lots of examples about POST request but no one seems to work.
After the request always get back the form page, as the server doesn't
receive or ignore the POST.
I'm using the last version of HttpClient (4.1).
This is the code I'm using to send the POST request (is the one in the
Apache site [
http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientFormLogin.java
link ]):

	DefaultHttpClient httpclient = new DefaultHttpClient();

        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
        
        HttpPost httpost = new
HttpPost("http://localhost/prova/index.html");

        List <NameValuePair> nvps = new ArrayList <NameValuePair>();
        nvps.add(new BasicNameValuePair("user", "prova"));
        nvps.add(new BasicNameValuePair("password", "prova"));

        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

        HttpResponse response = httpclient.execute(httpost);
        HttpEntity entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());
        if (entity != null) {
            entity.consumeContent();
        }

        System.out.println("Post logon cookies:");
        cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }

I'd like to know if the code I'm using is correct, how to retrieve the HTML
code of the target page of the form and if I can continue to navigate the
site without the session expires.

Thank you! And sorry if I did any English error!
-- 
View this message in context: http://old.nabble.com/Retrieve-HTML-code-after-POST-request-tp31107294p31107294.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message