1.8. Element post

<post
  url = anyURI
  encoding = any ASCII compatible encoding : "UTF-8"
  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. More precisely, the post element implements HTML5 — Form submission — Multipart form data using emulated input type="text" and input type="file" form fields.

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 ASCII compatible character encoding (ISO-8859-1, UTF-8, Windows-1252, etc) used by the form submission algorithms.

[Note]About special field named "_charset_"

When the POST request is submitted to the backend, a field element having its name attribute set to _charset_ and having an empty value:

<field name="_charset_"><value></value></field>

is automatically given a value corresponding to attribute encoding of element post (by default UTF-8). This way, the backend is informed of the character encoding used to encode the field names, values and file paths. See last example below.

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="file" 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 "UTF-8".

Examples:

<post url="http://localhost:8080/measure/archive" 
      encoding="ISO-8859-1" 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" 
      readResponse="true">
  <field name="username">
    <value>admin</value>
  </field>
  <field name="password">
    <value>changeit</value>
  </field>
</post>

<post url="http://localhost:8080/upload_photos">
  <field name="_charset_"><value></value></field>
  <field name="file1">
    <file name="/home/john/photos/la belle &#xE9;quipe.jpeg" 
          contentType="image/jpeg" />
  </field>
  <field name="copyTo1">
    <value>la belle &#xE9;quipe.jpg</value>
  </field>
  <field name="description1">
    <value>Oh la belle &#xE9;quipe que voil&#xE0;!</value>
  </field>
</post>