mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-23 20:12:09 +03:00
Add raw multipart form data sample.
This commit is contained in:
parent
2ec5b9c85a
commit
a90d78175a
@ -274,6 +274,32 @@ Content type can be specified or inferred based on the filename extension:
|
||||
|
||||
By default, content type is `application/octet-stream`.
|
||||
|
||||
As an alternative to a `[MultipartFormData]` section, multipart forms can also be sent with a [multiline string body]:
|
||||
|
||||
~~~hurl
|
||||
POST https://example.org/upload
|
||||
Content-Type: multipart/form-data; boundary="boundary"
|
||||
```
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="key1"
|
||||
|
||||
value1
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="upload1"; filename="data.txt"
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello World!
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="upload2"; filename="data.html"
|
||||
Content-Type: text/html
|
||||
|
||||
<div>Hello <b>World</b>!</div>
|
||||
--boundary--
|
||||
```
|
||||
~~~
|
||||
|
||||
> When using a multiline string body to send a multipart form data, files content must be inlined in the Hurl file.
|
||||
|
||||
|
||||
### Cookies
|
||||
|
||||
|
@ -113,6 +113,36 @@ field3: file,example.zip; application/zip
|
||||
|
||||
[Doc](/docs/request.md#multipart-form-data)
|
||||
|
||||
Multipart forms can also be sent with a [multiline string body]:
|
||||
|
||||
~~~hurl
|
||||
POST https://example.org/upload
|
||||
Content-Type: multipart/form-data; boundary="boundary"
|
||||
```
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="key1"
|
||||
|
||||
value1
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="upload1"; filename="data.txt"
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello World!
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="upload2"; filename="data.html"
|
||||
Content-Type: text/html
|
||||
|
||||
<div>Hello <b>World</b>!</div>
|
||||
--boundary--
|
||||
```
|
||||
~~~
|
||||
|
||||
In that case, files have to be inlined in the Hurl file.
|
||||
|
||||
[Doc](/docs/request.md#multiline-string-body)
|
||||
|
||||
|
||||
|
||||
### Posting a JSON Body
|
||||
|
||||
With an inline JSON:
|
||||
@ -468,6 +498,7 @@ bytes startsWith hex,efbbbf;
|
||||
[JSON body]: /docs/request.md#json-body
|
||||
[XML body]: /docs/request.md#xml-body
|
||||
[XML multiline string body]: /docs/request.md#multiline-string-body
|
||||
[multiline string body]: /docs/request.md#multiline-string-body
|
||||
[predicates]: /docs/asserting-response.md#predicates
|
||||
[JSONPath]: https://goessner.net/articles/JsonPath/
|
||||
[Basic authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#basic_authentication_scheme
|
||||
|
@ -1 +1,2 @@
|
||||
curl --form 'key1=value1' --form 'upload1=@tests_ok/data.txt;type=text/plain' --form 'upload2=@tests_ok/data.html;type=text/html' --form 'upload3=@tests_ok/data.txt;type=text/html' 'http://localhost:8000/multipart-form-data'
|
||||
curl --header 'Content-Type: multipart/form-data; boundary="boundary"' --data $'--boundary\nContent-Disposition: form-data; name="key1"\n\nvalue1\n--boundary\nContent-Disposition: form-data; name="upload1"; filename="data.txt"\nContent-Type: text/plain\n\nHello World!\n--boundary\nContent-Disposition: form-data; name="upload2"; filename="data.html"\nContent-Type: text/html\n\n<div>Hello <b>World</b>!</div>\n--boundary\nContent-Disposition: form-data; name="upload3"; filename="data.txt"\nContent-Type: text/html\n\nHello World!\n--boundary--\n' 'http://localhost:8000/multipart-form-data'
|
||||
|
@ -1,12 +1,39 @@
|
||||
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/multipart-form-data</span></span>
|
||||
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"></span><span class="comment"># On can use the dedicated [MultipartFormData] section</span>
|
||||
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/multipart-form-data</span></span>
|
||||
<span class="line section-header">[MultipartFormData]</span>
|
||||
<span class="line"><span class="string">key1</span><span>:</span> <span class="string">value1</span></span>
|
||||
<span class="line"><span class="string">upload1</span>: file,<span class="filename">data.txt</span>;</span>
|
||||
<span class="line"><span class="string">upload2</span>: file,<span class="filename">data.html</span>;</span>
|
||||
<span class="line"><span class="string">upload3</span>: file,<span class="filename">data.txt</span>; <span class="string">text/html</span></span>
|
||||
</span><span class="response"><span class="line"></span>
|
||||
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
||||
</span></span><span class="line"></span>
|
||||
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
||||
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"></span><span class="comment"># Or, as an alternative to the [MultipartFormData] section, we can just use</span>
|
||||
<span class="line"></span><span class="comment"># a multiline string body, constructing boundaries by hand (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST).</span>
|
||||
<span class="line"></span><span class="comment"># The downside of this method is that we must inline the files content (for the moment).</span>
|
||||
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/multipart-form-data</span></span>
|
||||
<span class="line"><span class="string">Content-Type</span><span>:</span> <span class="string">multipart/form-data; boundary="boundary"</span></span>
|
||||
<span class="multiline"><span class="line">```</span>
|
||||
<span class="line">--boundary</span>
|
||||
<span class="line">Content-Disposition: form-data; name="key1"</span>
|
||||
<span class="line"></span>
|
||||
</code></pre>
|
||||
<span class="line">value1</span>
|
||||
<span class="line">--boundary</span>
|
||||
<span class="line">Content-Disposition: form-data; name="upload1"; filename="data.txt"</span>
|
||||
<span class="line">Content-Type: text/plain</span>
|
||||
<span class="line"></span>
|
||||
<span class="line">Hello World!</span>
|
||||
<span class="line">--boundary</span>
|
||||
<span class="line">Content-Disposition: form-data; name="upload2"; filename="data.html"</span>
|
||||
<span class="line">Content-Type: text/html</span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><div>Hello <b>World</b>!</div></span>
|
||||
<span class="line">--boundary</span>
|
||||
<span class="line">Content-Disposition: form-data; name="upload3"; filename="data.txt"</span>
|
||||
<span class="line">Content-Type: text/html</span>
|
||||
<span class="line"></span>
|
||||
<span class="line">Hello World!</span>
|
||||
<span class="line">--boundary--</span>
|
||||
<span class="line">```</span></span>
|
||||
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
||||
</span></span></code></pre>
|
||||
|
@ -1,11 +1,38 @@
|
||||
# On can use the dedicated [MultipartFormData] section
|
||||
POST http://localhost:8000/multipart-form-data
|
||||
[MultipartFormData]
|
||||
key1: value1
|
||||
upload1: file,data.txt;
|
||||
upload2: file,data.html;
|
||||
upload3: file,data.txt; text/html
|
||||
|
||||
HTTP 200
|
||||
|
||||
|
||||
# Or, as an alternative to the [MultipartFormData] section, we can just use
|
||||
# a multiline string body, constructing boundaries by hand (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST).
|
||||
# The downside of this method is that we must inline the files content (for the moment).
|
||||
POST http://localhost:8000/multipart-form-data
|
||||
Content-Type: multipart/form-data; boundary="boundary"
|
||||
```
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="key1"
|
||||
|
||||
value1
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="upload1"; filename="data.txt"
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello World!
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="upload2"; filename="data.html"
|
||||
Content-Type: text/html
|
||||
|
||||
<div>Hello <b>World</b>!</div>
|
||||
--boundary
|
||||
Content-Disposition: form-data; name="upload3"; filename="data.txt"
|
||||
Content-Type: text/html
|
||||
|
||||
Hello World!
|
||||
--boundary--
|
||||
```
|
||||
HTTP 200
|
||||
|
@ -1 +1 @@
|
||||
{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/multipart-form-data","multipart_form_data":[{"name":"key1","value":"value1"},{"name":"upload1","filename":"data.txt"},{"name":"upload2","filename":"data.html"},{"name":"upload3","filename":"data.txt","content_type":"text/html"}]},"response":{"status":200}}]}
|
||||
{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/multipart-form-data","multipart_form_data":[{"name":"key1","value":"value1"},{"name":"upload1","filename":"data.txt"},{"name":"upload2","filename":"data.html"},{"name":"upload3","filename":"data.txt","content_type":"text/html"}]},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/multipart-form-data","headers":[{"name":"Content-Type","value":"multipart/form-data; boundary=\"boundary\""}],"body":{"type":"text","value":"--boundary\nContent-Disposition: form-data; name=\"key1\"\n\nvalue1\n--boundary\nContent-Disposition: form-data; name=\"upload1\"; filename=\"data.txt\"\nContent-Type: text/plain\n\nHello World!\n--boundary\nContent-Disposition: form-data; name=\"upload2\"; filename=\"data.html\"\nContent-Type: text/html\n\n<div>Hello <b>World</b>!</div>\n--boundary\nContent-Disposition: form-data; name=\"upload3\"; filename=\"data.txt\"\nContent-Type: text/html\n\nHello World!\n--boundary--\n"}},"response":{"status":200}}]}
|
||||
|
@ -1,4 +1,3 @@
|
||||
# curl -v -F key1=value1 -F upload1=@tests_ok/data.txt -Fupload2=@tests_ok/data.html http://localhost:8000/multipart-form-data
|
||||
from app import app
|
||||
from flask import request
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
curl --form 'key1=value1' --form 'upload1=@tests_ok\data.txt;type=text/plain' --form 'upload2=@tests_ok\data.html;type=text/html' --form 'upload3=@tests_ok\data.txt;type=text/html' 'http://localhost:8000/multipart-form-data'
|
||||
curl --header 'Content-Type: multipart/form-data; boundary="boundary"' --data $'--boundary\nContent-Disposition: form-data; name="key1"\n\nvalue1\n--boundary\nContent-Disposition: form-data; name="upload1"; filename="data.txt"\nContent-Type: text/plain\n\nHello World!\n--boundary\nContent-Disposition: form-data; name="upload2"; filename="data.html"\nContent-Type: text/html\n\n<div>Hello <b>World</b>!</div>\n--boundary\nContent-Disposition: form-data; name="upload3"; filename="data.txt"\nContent-Type: text/html\n\nHello World!\n--boundary--\n' 'http://localhost:8000/multipart-form-data'
|
||||
|
Loading…
Reference in New Issue
Block a user