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<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.
>
>
> 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: [email protected]
For additional commands, e-mail: [email protected]