mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
implement client with bash
This commit is contained in:
parent
02042ae26f
commit
7c34cf235b
@ -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``
|
||||
|
@ -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
11
multipart/client.sh
Executable 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
5
multipart/example.png
Normal file
@ -0,0 +1,5 @@
|
||||
------------------------------4ebf00fbcf09
|
||||
Content-Disposition: form-data; name="example"
|
||||
|
||||
test
|
||||
------------------------------4ebf00fbcf09--
|
Loading…
Reference in New Issue
Block a user