Hello Roland, hello Oleg,

many thanks for your help! I've included Live HTTP Header 0.12 into my
Firefox (beforde that I've used the Etherscan Analyzer which packets were
really hard to read...) - that's really a nice plugin! 

Now I did many things, unfortunately most of them without knowing with I'm
doing. But the result is, that it now works... :-)

Here are some thoughts what might have been wrong:
- My first request was a direct POST-Request. At this time there was no
session running (i.e. I've had no cookie) so it might be, that the Webserver
was unable to identify me (now I first GET the page that contains the login
form)?
- There might have been wrong URLs (as you mentioned, Roland)?

Perhaps you can tell me what was wrong or what I can optimize with my code
(see below)!? 
If you don't have the time or simply don't like to give a comment I don't
mind. But if you do so, I would be once again very grateful ;-)

Btw: I've changed my logging preferences to the wire log only ;-)

Cheers!
André


Here's my new class:
----------------------------------------------------------------------------
--------------------------------------------------------
package de.kolell.webF;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

import java.io.*;

public class WebF {

        private static HttpClient client = new HttpClient();

        public static void main(String[] args) {

                /*
                 * Request to receive the Cookie
                 */
                
                // Create a method instance.
                GetMethod method = new
GetMethod("http://ebwl.euro-fh-campus.de/campus/index.php";);

                try {
                        // Execute the method.
                        int statusCode = client.executeMethod(method);

                        if (statusCode != HttpStatus.SC_OK) {
                                System.err.println("Method failed: " +
method.getStatusLine());
                        }
                } catch (HttpException e) {
                        System.err.println("Fatal protocol violation: " +
e.getMessage());
                        e.printStackTrace();
                } catch (IOException e) {
                        System.err.println("Fatal transport error: " +
e.getMessage());
                        e.printStackTrace();
                } finally {
                        // Release the connection.
                        method.releaseConnection();
                }

                

                /*
                 * Login via POST
                 */
                
                // Create a method instance.
                PostMethod pmethod = new
PostMethod("http://ebwl.euro-fh-campus.de/campus/index.php";);

                // Provide custom retry handler is necessary
                NameValuePair[] data = { new NameValuePair("loginjetzt",
"nein"),
                                new NameValuePair("username", "904308701"),
                                new NameValuePair("password", "FOO") };
                pmethod.setRequestBody(data);

                try {
                        // Execute the method.
                        int statusCode = client.executeMethod(pmethod);

                        if (statusCode != HttpStatus.SC_OK) {
                                System.err.println("Method failed: " +
pmethod.getStatusLine());
                        }
                } catch (HttpException e) {
                        System.err.println("Fatal protocol violation: " +
e.getMessage());
                        e.printStackTrace();
                } catch (IOException e) {
                        System.err.println("Fatal transport error: " +
e.getMessage());
                        e.printStackTrace();
                } finally {
                        // Release the connection.
                        pmethod.releaseConnection();
                }
                
                
                
                /*
                 * Fetch marks
                 */

                // Create a method instance.
                GetMethod gmethod = new
GetMethod("http://ebwl.euro-fh-campus.de/campus/information/scorecard/noten.
php");

                try {
                        // Execute the method.
                        int statusCode = client.executeMethod(gmethod);

                        if (statusCode != HttpStatus.SC_OK) {
                                System.err.println("Method failed: " +
gmethod.getStatusLine());
                        }

                        // Read the response body.
                        Reader is = new
InputStreamReader(gmethod.getResponseBodyAsStream());
                        BufferedReader in = new BufferedReader(is);
                        for (String s; (s = in.readLine()) != null;)
                                System.out.println(s);

                } catch (HttpException e) {
                        System.err.println("Fatal protocol violation: " +
e.getMessage());
                        e.printStackTrace();
                } catch (IOException e) {
                        System.err.println("Fatal transport error: " +
e.getMessage());
                        e.printStackTrace();
                } finally {
                        // Release the connection.
                        gmethod.releaseConnection();
                }
        }
}
----------------------------------------------------------------------------
--------------------------------------------------------




-----Ursprüngliche Nachricht-----
Von: Roland Weber [mailto:[EMAIL PROTECTED] 
Gesendet: Dienstag, 28. März 2006 18:52
An: HttpClient User Discussion
Betreff: Re: AW: Problem with Cookie!? URL!?

Hello Andre,

> (at first I thought that the URLs would be same, hence I used "url" 
> als a variable; in some way the URLs are really the same, only the 
> parameters are different!?).

A URL with path /campus/ is quite different from a URL with path
/campus/index.php and query string Lernbar=9c68975b63532db9c8e19c251b59ab2e
If you don't believe that, try those two...
http://www.google.com/
http://www.google.com/search?q=whatever
They also only differ mainly by the parameters :-)

You'll have to figure out what the server doesn't like about the request you
send there. Maybe some parameters missing in the POST?
The most promising approach - if staring intently at the code and the web
page you are simulating doesn't work - is to get a sniffer and monitor the
HTTP communication between your favorite browser and the server. Then
compare with the messages sent by HttpClient.
There is a recent mail thread that suggest a few sniffer programs:
http://mail-archives.apache.org/mod_mbox/jakarta-httpclient-user/200603.mbox
/[EMAIL PROTECTED]

I recommend you reduce the debug output to the wire log only. The context
log is really only helpful when we need to trace a bug in HttpClient, not as
long as you have application level problems.
(I can imagine Oleg's smile right now :-)

cheers from rainy Stuttgart,
  Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to