HTTP client post data - Factor Documentation (original) (raw)
HTTP POST, PUT, and PATCH request words take a data parameter, which can be one of the following:
• | a byte-array: the data is sent the server without further encoding |
---|---|
• | a string: the data is encoded and then sent as a series of bytes |
• | an assoc: the assoc is interpreted as a series of form parameters, which are encoded with assoc>query |
• | an input stream: the contents of the input stream are transmitted to the server without being read entirely into memory - this is useful for large requests |
• | f denotes that there is no post data |
• | a post-data tuple, for additional control |
When passing a stream, you must ensure the stream is closed afterwards. The best way is to use with-disposal or Deterministic resource disposal. For example,
"my-large-post-request.txt" ascii [ URL" http://www.my-company.com/web-service" http-post ] with-disposal
An internal word used to convert objects to post-data instances: >post-data ( object -- post-data )