Open kinoooolu opened 7 years ago
POST /application/deploy HTTP/1.1 Authorization: Basic YXBpOm1hbmFnZXI= Content-Length: 1780 Content-Type: multipart/form-data; boundary=ChnId1zKDLlln7wtZzoeIt6dmuBTcG_C Host: localhost:22222 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_45) Accept-Encoding: gzip,deflate
I'm not quite sure how you use form
in your code. An example is as following:
server.post(eq(form("name"), "dreamhead")).response("foobar");
Refer to form for more information.
I'm trying to use JSON format to mock file upload (a Multipart request), but moco cannot support it.
The reason is Multipart request contains a generated boundary:
{
"description": "user_can_upload_file",
"request": {
"uri": "/api/files",
"method": "POST",
"headers": {
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryKgNrZfGWAQ59LuVd"
},
"file": "api/multipart.txt"
},
"response": {
"status": 201,
"headers": {
"Location": "http://{host}:{port}/api/files/{file-id}"
}
}
}
api/multipart.txt
:
------WebKitFormBoundaryKgNrZfGWAQ59LuVd
Content-Disposition: form-data; name="file"; filename="hello.txt"
Content-Type: text/plain
hello
------WebKitFormBoundaryKgNrZfGWAQ59LuVd
Content-Disposition: form-data; name="name"
dreamhead
------WebKitFormBoundaryKgNrZfGWAQ59LuVd--
Hi Dreamhead As tittle, when I send multipart/form request, 400 bad request will be got... Any solution or workaround for this? Thanks!