1
0
mirror of https://github.com/actix/examples synced 2024-11-28 00:12:57 +01:00

implement client with bash

This commit is contained in:
Cristian Re 2019-08-13 11:29:16 -03:00
parent 02042ae26f
commit 7c34cf235b
4 changed files with 24 additions and 43 deletions

View File

@ -12,13 +12,14 @@ cargo run (or ``cargo watch -x run``)
# Started http server: 127.0.0.1:8080
```
### client
### browser
- ``pip install aiohttp``
- ``python client.py``
- go to ``http://localhost:8080``
- upload file
- you should see the action reflected in server console
### client (optional)
- ``./client.sh``
- you must see in server console multipart fields
if ubuntu :
- ``pip3 install aiohttp``
- ``python3 client.py``

View File

@ -1,36 +0,0 @@
#!/usr/bin/env python3
# This script could be used for actix-web multipart example test
# just start server and run client.py
import asyncio
import aiohttp
async def req1():
with aiohttp.MultipartWriter() as writer:
writer.append('test')
writer.append_json({'passed': True})
resp = await aiohttp.ClientSession().request(
"post", 'http://localhost:8080/',
data=writer, headers=writer.headers)
print(resp)
assert 200 == resp.status
async def req2():
with aiohttp.MultipartWriter() as writer:
writer.append('test')
writer.append_json({'passed': True})
writer.append(open('src/main.rs'))
resp = await aiohttp.ClientSession().request(
"post", 'http://localhost:8080/',
data=writer, headers=writer.headers)
print(resp)
assert 200 == resp.status
loop = asyncio.get_event_loop()
loop.run_until_complete(req1())
loop.run_until_complete(req2())

11
multipart/client.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
function SubmitFile () {
curl -X POST \
-H "Content-Type: multipart/related" \
--form "data=@example.png;type=image/png" http://localhost:8080
}
SubmitFile & SubmitFile & SubmitFile &
SubmitFile & SubmitFile & SubmitFile &
SubmitFile & SubmitFile & SubmitFile

5
multipart/example.png Normal file
View File

@ -0,0 +1,5 @@
------------------------------4ebf00fbcf09
Content-Disposition: form-data; name="example"
test
------------------------------4ebf00fbcf09--