Hi, thanks for your reply. I tried that out but that does not work for me... If I set the VM Arguments it throws a ClassNotFoundException. If not, the program works without logging.
I would need logging in my application itself, not in the console. I need the data to do the next step and the application should log the traffic to a file or something like that in production mode. I tried the following: System: Windows 64bit Java 6 Update22 32bit Download: Eclipse Classic 3.6.1 32bit Windows Download: httpcomponents-client-4.0.3-bin-with-dependencies.zip from http://hc.apache.org/downloads.cgi Open Eclipse > select workspace > .\workspace New JavaProject > WireTestProject > JavaSE-1.6 >Finish New package wiretest Right klick project > BuildPath > add external archives > Open: "httpmime-4.0.3.jar" "apache-mime4j-0.6.jar" "commons-codec-1.3.jar" "commons-logging-1.1.1.jar" "httpclient-4.0.3.jar" "httpcore-4.0.1.jar" New Class TestWireLogging: package wiretest; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; public class TestWireLogging { public static void main(String[] args) throws Exception{ String url = "http://google.at"; System.out.println(url); HttpClient httpclient= new DefaultHttpClient(); HttpGet httpost = new HttpGet(url); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); String content = EntityUtils.toString(entity); System.out.println(content); System.err.println("test"); } } Run > run configurations > new java Application > Main class: wiretest.TestWireLogging VM Arguments: org.apache.http.impl.conn.level = FINEST org.apache.http.impl.client.level = FINEST org.apache.http.client.level = FINEST org.apache.http.level = FINEST Apply > Run > Result: java.lang.NoClassDefFoundError: org/apache/http/impl/conn/level Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.conn.level at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Exception in thread "main" Thanks, Flo -------- Original-Nachricht -------- > Datum: Sat, 23 Oct 2010 17:51:33 +0100 > Von: Carl-Gustaf Harroch <[email protected]> > An: HttpClient User Discussion <[email protected]> > Betreff: Re: How to get http headers using httpclient > Hi Flo, > > Instead of polluting your code, why not put it in the run > configuration within eclipse: > > Run -> Run configuration -> new Java application -> arguments -> VM > arguments and paste the following (change accordingly): > > org.apache.http.impl.conn.level = FINEST > org.apache.http.impl.client.level = FINEST > org.apache.http.client.level = FINEST > org.apache.http.level = FINEST > > You should have everything dumped within the console. > > ./Carl > > > On 23 October 2010 16:39, <[email protected]> wrote: > > Hi All, > > > > Is there an example how to get the whole http protocol? > > I would need the request, the response header and content. > > I tried out to log them but I don’t know how to use the logging api > right, and I couldn’t find any example for that. > > I want to the information in my application and log all the traffic. > > Here is what I tried out yet. > > I use: Eclipse 3.6.1 and httpclient 4.0.3 > > > > import org.apache.http.HttpEntity; > > import org.apache.http.HttpResponse; > > import org.apache.http.client.HttpClient; > > import org.apache.http.client.methods.HttpGet; > > import org.apache.http.impl.client.DefaultHttpClient; > > import org.apache.http.util.EntityUtils; > > > > > > public class TestWireLogging { > > public static void main(String[] args) throws Exception{ > > System.setProperty("org.apache.commons.logging.Log" , > "org.apache.commons.logging.impl.SimpleLog"); > > > > System.setProperty("org.apache.commons.logging.simplelog.showdatetime","true"); > > > > System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire" > ,"DEBUG"); > > > > System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient" > ,"ERROR"); > > String url = "http://google.at"; > > System.out.println(url); > > > > HttpClient httpclient= new DefaultHttpClient(); > > > > HttpGet httpost = new HttpGet(url); > > > > HttpResponse response = > httpclient.execute(httpost); > > HttpEntity entity = response.getEntity(); > > > > > > String content = EntityUtils.toString(entity); > > System.out.println(content); > > System.err.println("test"); > > } > > } > > > > If someone could give me an example, > > I would be very grateful. > > > > Thanks, > > Flo > > > > -- > > Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief! > > Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail > > > > --------------------------------------------------------------------- > > 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] > -- Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
