commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Ball <ba...@webslingerZ.com>
Subject RE: HttpClient development
Date Mon, 06 May 2002 21:47:32 GMT
On Mon, 2002-05-06 at 17:43, Donald Ball wrote:

> anyway, attached is a short usage sample document for HttpClient. i'll
> see about fleshing it out if anyone has any comments.

er, okay, looks like jakarta's mail server silently drops attachments.
here it is inline.

- donald

<?xml version="1.0"?>
<document>
  <properties>
    <title>Usage</title>
    <author email="commons-dev@jakarta.apache.org">Commons Documentation Team</author>
    <author email="balld@apache.org">Donald Ball</author>
    <revision>$Id$</revision>
  </properties>
  <body>
    <section name="Usage">
      <p>Here is a short example program to help you get up to speed with HttpClient.
It checks to see if a resource exists using the <code>HEAD</code> method.</p>
      <source><![CDATA[
public boolean testURL(String url) {

    HttpMultiClient client = new HttpMultiClient();
    HttpUrlMethod method = null;
    int status = -1;

    try {
        method = new UrlHeadMethod(url);
    } catch (MalformedURLException e) {
        throw new RuntimeException("Could not test malformed URL: "+
                                   url + ": " + e.getMessage());
    }
    method.setFollowRedirects(true);
    status = client.executeMethod(method);
    return (status == HttpStatus.SC_OK);

}
]]></source>
      <p>If you have many requests to make, you will probably want to reuse these objects.
<code>HttpMultiClient</code>'s executeMethod method is threadsafe, while the <code>HttpUrlMethod</code>
objects can be recycled after they're used.</p>
    </section>
  </body>
</document>

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message