Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Java Shell
Failed to load latest commit information.
src add additional unit test for attribute matching
.classpath Progress with templates. Now failing test case for list expansion
.gitignore Add degraph config
.project new eclipse formatting for dot files
LICENSE.txt mvn license:format Update the README
pom.xml add xml output for cobertura coverage mvn license:format

mechanize for java

mechanize is a stateful HTTP web services client library (RESTful) with support for HTML, JSON, and XML services. Because mechanize is stateful and allow inspection of web resources, it naturally support GET-then-POST semantics and helps avoid hard-coding clients.

See the Mechanize Wiki for more details and opinions on how RESTful clients should behave.


  • 1.x is the original port of mechanize to java. This will be maintained for bug fixes and possibly other enhancements.
  • 2.x is the modularized version to separate HTML, JSON, and XML into separate a la carte packages. Also the JSON linking dev will be here.

Here is a testcase showing mechanize at work with HTML:

    @Test public void testGooglePageSearchForm() {
        MechanizeAgent agent = new MechanizeAgent();
        Document page = agent.get("");
        Form form = page.form("f");
        form.get("q").set("mechanize java");
        Resource response = form.submit();
        assertTrue(response.getTitle().startsWith("mechanize java"));

Here is a testcase showing mechanize using a Google JSON web service:

    public void testGoogleApi() throws JSONException {
        MechanizeAgent agent = new MechanizeAgent();
        JsonDocument json = agent.doRequest(googleUrl).add("shortUrl", shortUrl).add("projection", "FULL").get();

        assertEquals(longUrl, json.getRoot().find("longUrl").getValue());

        String value = json.getRoot().find("analytics month countries#US count").getValue();
        assertTrue(value, Integer.valueOf(value)>=1);

Include this library (or download) from the Maven repository:

Something went wrong with that request. Please try again.