Re: Using HttpUnit without WebConversation and WebResponse
"Jesper Sahner" <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Russell, Thanks for your quick reply! Actually your response solves another problem that I faced. I will explain this. At first I tried something like your proposal. I wrote the String to a file 'test.htm' which was located in a local webserver library (I am running Apache as a local Webserver). I then accessed the file in the standard way using: WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( "http://localhost/test.htm" ); However this doesn't work because the 'test.htm'-file contains a reference to another file 'empty.html', which is not present. The following exception is thrown: Exception in thread "main" com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 Not Found [http://localhost/empty.html] On the other hand the file 'test.htm' can be opened in e.g. IE despite the broken reference to 'empty.html', so.. But your solution actually solves this problem using URLConnection. I am not sure I understand exactly why. Can you explain this? Regards, Jesper >From: Russell Gold <[email protected]> >Reply-To: [email protected] >To: [email protected] >Subject: Re: [Httpunit-develop] Using HttpUnit without WebConversation and >WebResponse >Date: Sat, 18 Mar 2006 22:05:22 -0500 > > >On Mar 18, 2006, at 8:37 PM, Jesper Sahner wrote: > >>Hi! >> >>Normally when you use HttpUnit you use it like this: >>WebConversation wc = new WebConversation(); >>WebResponse resp = wc.getResponse( "http://www.httpunit.org/doc/ >>cookbook.html" ); >>WebTable table = resp.getTables()[0]; >>... >> >>Now say that you already have the response in e.g. a String (or a Stream >>of some kind) and just want to use the WebTable-part. How can the >>WebConversation- and the WebResponse-part be omitted and be replaced with >>e.g. a String? > >If you can write the string to a file, you can do something like: > >WebResponse wr = WebResponse.newResponse( New URLConnection ( >"file:path-to-the-file" ) ); > > >------------------------------------------------------- >This SF.Net email is sponsored by xPML, a groundbreaking scripting language >that extends applications into web and mobile media. Attend the live >webcast >and join the prime developer group breaking into this new coding territory! >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 >_______________________________________________ >Httpunit-develop mailing list >[email protected] >https://lists.sourceforge.net/lists/listinfo/httpunit-develop ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642