<?xml version="1.0" encoding="ISO-8859-1"?>

<document>

  <properties>
    <title>Put Method</title>
    <author email="adrian@ephox.com">Adrian Sutton</author>
    <revision>$Id$</revision>
  </properties>

  <body>

    <section name="Introduction">
      <p>The PUT method requests that the enclosed entity be stored under the
      supplied URL.  If the URL refers to an already existing resource, the
      enclosed entity <i>should</i> be considered as a modified version of the
      one residing on the origin server.  If the URL does not point to an
      existing resource, and that URL is capable of being defined as a new
      resource by the requesting user agent, the origin server can create the
      resource with that URL.</p>

      <p>If the request passes through a cache and the URL identifies one or
      more currently cached entities, those entries <i>should</i> be treated as
      stale.  Responses to this method are not cacheable.</p>

      <p>The fundamental difference between <a href="post.html">POST</a> and
      PUT requests is reflected in the different meaning of the request URL.
      The URL in a POST request identifies the resource that will handle the
      enclosed entity.  That resource might be a data-accepting process, a
      gateway to some other protocol, or a separate entity that accepts
      annotations.  In contrast, the URL in a PUT request identifies the entity
      enclosed with the request -- the user agent knows what URL is intended
      and the server <b>must not</b> attempt to apply the request to some other
      resource.</p>

      <p>Unless otherwise specified for a particular entity-header, the
      entity-headers in the PUT request <i>should</i> be applied to the
      resource created or modified by the PUT.</p>
    </section>

    <section name="Typical Usage">
      <p>The put method is very simple, it takes a URL to put to and requires
      that the body of the request method be set to the data to upload.  The
      body can be set with an input stream or a string.</p>

      <source><![CDATA[
        PutMethod put = new PutMethod("http://jakarta.apache.org");
        put.setRequestBody(new FileInputStream("UploadMe.gif"));
        // execute the method and handle any error responses.
        ...
        // Handle the response.  Note that a successful response may not be
        // 200, but may also be 201 Created, 204 No Content or any of the other
        // 2xx range responses.
      ]]>
      </source>
    </section>

    <section name="Common Problems">
      <p>The PUT method is not widely supported on public servers due to
      security concerns and generally FTP is used to upload new and modified
      files to the webserver.  Before executing a PUT method on a URL, it may
      be worth checking that PUT is supported using the <a
      href="options.html">OPTIONS</a> method.</p>
    </section>

    <section name="RFC Section">
        <p>The put method is defined in section 9.6 of <a
        href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>.</p>
    </section>

  </body>

</document>
