[Httpunit-commit] CVS: httpunit/examples Example.java,1.2,1.3
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-11-25 13:52:48
|
Update of /cvsroot/httpunit/httpunit/examples
In directory sc8-pr-cvs1:/tmp/cvs-serv30205/examples
Modified Files:
Example.java
Log Message:
Updated Example.java to point to always-on page
Index: Example.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/examples/Example.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Example.java 28 Jan 2002 05:05:30 -0000 1.2
+++ Example.java 25 Nov 2002 13:52:45 -0000 1.3
@@ -1 +1 @@
-import com.meterware.httpunit.*;
import java.io.IOException;
import java.net.MalformedURLException;
import org.xml.sax.*;
public class Example {
public static void main( String[] params ) {
try {
WebRequest request;
WebResponse response;
WebConversation conversation = new WebConversation();
request = new GetMethodWebRequest( "http://www.meterware.com/servlet/TopSecret" );
response = conversation.getResponse( request );
System.out.println( response );
WebForm loginForm = response.getForms()[0];
request = loginForm.getRequest();
request.setParameter( "name", "master" );
response = conversation.getResponse( request );
System.out.println( response.getText() );
} catch (Exception e) {
System.err.println( "Exception: " + e );
}
}
}
\ No newline at end of file
+import com.meterware.httpunit.*;
/** This is a simple example of using HttpUnit to read and understand web pages. **/
public class Example {
public static void main( String[] params ) {
try {
// create the conversation object which will maintain state for us
WebConversation wc = new WebConversation();
// Obtain the main page on the meterware web site
WebRequest request = new GetMethodWebRequest( "http://www.meterware.com" );
WebResponse response = wc.getResponse( request );
// find the link which contains the string "HttpUnit" and click it
WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "HttpUnit" );
response = httpunitLink.click();
// print out the number of links on the HttpUnit main page
System.out.println( "The HttpUnit main page contains " + response.getLinks().length + " links" );
} catch (Exception e) {
System.err.println( "Exception: " + e );
}
}
}
\ No newline at end of file
|