1.8. Element `post`
Prev | 1. Reference | Next

### 1.8. Element `post`

    <post
      url = anyURI
      encoding = "ISO-8859-1" | "UTF-8" : "ISO-8859-1"
      readResponse = boolean : false
    >
      Content: [ field ]+
    </post>

    <field
      name = Form field name (US-ASCII only)
    >
      Content: value | file
    </field>

    <value>
      Content: xs:string
    </value>

    <file
      name = Path
      contentType = Content type
    />

Emulates an HTML form possibly containing `input type="file"` elements.

The `post` element posts the contents of the emulated form to the CGI or Servlet specified by attribute `url`.

The body of the `POST` request is encoded as "`multipart/form-data`" if the `post` element contains at least one `file` descendant element. Otherwise this body is encoded as "`application/x-www-form-urlencoded`".

Optional attribute `encoding` specifies the character encoding used to escape accented characters when the body of the `POST` request is encoded as "`application/x-www-form-urlencoded`".

An emulated form field has a name specified by required attribute `name`. There are two type of fields:

value

  Emulates `input type="text"` or `input type="hidden"` elements found in an HTML form. The content of this element, a possibly empty string, specifies the value of the field.

file

  Emulates `input type="`f`ile"` elements found in an HTML form. The `name` attribute of this element specifies the filename of the file to be uploaded.

  Unless specified, the content type of the file is guessed using the extension of the filename. If the filename ends with:

  .zip

    the content type is supposed to be `application/zip`;

  .jar

    the content type is supposed to be `application/x-java-archive`;

  .xml

    the content type is supposed to be `text/xml`.

  Otherwise, the content type is supposed to be `application/octet-stream`.

If attribute `readResponse` is specified with value `true`, this element returns the response of the server. Otherwise, this element returns no result at all.

Moreover, for this element to return a result, the server must respond to the post request with a success code different from "`No Content`" (204) and must send "`text/*`" data (e.g. "`text/plain`", "`text/html`", etc). If the content type of the sent data has no charset, the data is read as a string using charset "`ISO-8859-1`".

Examples:

    <post url="http://localhost:8080/measure/archive">
      <field name="op">
        <value>add</value>
      </field>
      <field name="user">
        <value>%U</value>
      </field>
      <field name="data">
        <file name="/tmp/1052_3_CO_3.1R" />
      </field>
    </post>

    <post url="http://localhost:8080/measure/archive"
          readResponse="true">
      <field name="op">
        <value>add</value>
      </field>
      <field name="user">
        <value>%U</value>
      </field>
      <field name="interactive">
        <value>false</value>
      </field>
      <field name="data">
        <file name="1052_3_CO_3.1R"
              contentType="text/xml; charset=ISO-8859-1" />
      </field>
    </post>

    <post url="http://www.acme.com/login"
          encoding="UTF-8" readResponse="true">
      <field name="username">
        <value>admin</value>
      </field>
      <field name="password">
        <value>changeit</value>
      </field>
    </post>

Prev | Up | Next
1.7. Element `upload` | Home | 1.9. Element `print`