Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 83153 invoked from network); 9 Mar 2011 23:22:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Mar 2011 23:22:58 -0000 Received: (qmail 3785 invoked by uid 500); 9 Mar 2011 23:22:58 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 3758 invoked by uid 500); 9 Mar 2011 23:22:58 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 3738 invoked by uid 99); 9 Mar 2011 23:22:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Mar 2011 23:22:57 +0000 X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.26 as permitted sender) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Mar 2011 23:22:52 +0000 Received: from isper.nabble.com ([192.168.236.156]) by sam.nabble.com with esmtp (Exim 4.69) (envelope-from ) id 1PxSi7-0005Vq-9d for httpclient-users@hc.apache.org; Wed, 09 Mar 2011 15:22:32 -0800 Message-ID: <31111439.post@talk.nabble.com> Date: Wed, 9 Mar 2011 15:22:31 -0800 (PST) From: Desholo To: httpclient-users@hc.apache.org Subject: Re: Retrieve HTML code after POST request In-Reply-To: <1299701503.1975.9.camel@ubuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: duccio.magini@gmail.com References: <31107294.post@talk.nabble.com> <1299701503.1975.9.camel@ubuntu> olegk wrote: > > On Wed, 2011-03-09 at 07:21 -0800, Desholo wrote: >> 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 cookies = httpclient.getCookieStore().getCookies(); >> >> HttpPost httpost = new >> HttpPost("http://localhost/prova/index.html"); >> >> List nvps = new ArrayList (); >> 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. > > > Login related questions are notoriously difficult as different sites > tend to handle authentication differently. It is very unlikely you are > going to get any help unless you are prepared to do most of the work by > yourself: (1) capture HTTP sessions generated by a browser during the > authentication process using a packet sniffer or a browser plugin (2) > simulate the process using HttpClient. > > Oleg > Thanks for help Oleg! I would like to understand how HttpClient works, so I created locally a simple login form with php, without any cookie or session variable. I'm unable to understand if the code above works! This is what I get from the debug outputs: Login form get: HTTP/1.1 200 OK Post logon cookies: None What interest me most is to know how to see if the POST request is successful or not. And so i would like to retrieve the HTML code of the response page. Thank you again, Duccio -- View this message in context: http://old.nabble.com/Retrieve-HTML-code-after-POST-request-tp31107294p31111439.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