I'm trying to create multipart POST call using RestAssured, but I don't know how to get any boundary there. I tried this code, but it doesn't work.
given().contentType("multipart/form-data")
.config(config.multiPartConfig(multiPartConfig().defaultFileName(null).defaultBoundary("WebKitFormBoundary123")))
.multiPart("file", new File("src\test\resources\picture.png"), "image/png")
.multiPart("name", "picture.png")
.multiPart("userId", 1426373, "text/plain")
.log().all()
.when().post(URL).then().log().all().statusCode(200);
Log
Request method: POST
Request URI: URL
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=application/json
Cookies: <none>
Multiparts: ------------
Content-Disposition: form-data; name = file; filename = picture.png
Content-Type: image/png
src\test\resources\picture.png
------------
Content-Disposition: form-data; name = name
Content-Type: text/plain
picture.png
------------
Content-Disposition: form-data; name = userId
Content-Type: text/plain
1426373
Wanted result:
------WebKitFormBoundary123
Content-Disposition: form-data; name="file"; filename="picture.png"
Content-Type: image/png
src\test\resources\picture.png
------WebKitFormBoundary123
Content-Disposition: form-data; name="name"
picture.png
------WebKitFormBoundary123
Content-Disposition: form-data; name="userId"
1426373
------WebKitFormBoundary123--
So, how do I get ------WebKitFormBoundary123 in the request multipart form?
UPDATE: If I use this:
contentType("multipart/form-data; boundary=--WebKitFormBoundary123")
I will get this, which still doesn't look the same and it doesn't work
Request method: POST
Request URI: URL
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=application/json; boundary=--WebKitFormBoundary123
Cookies: <none>
Multiparts: ------------
Content-Disposition: form-data; boundary=--WebKitFormBoundary123; name = file; filename = picture.png
Content-Type: image/png
src\test\resources\picture.png
------------
Content-Disposition: form-data; boundary=--WebKitFormBoundary123; name = name
Content-Type: text/plain
picture.png
------------
Content-Disposition: form-data; boundary=--WebKitFormBoundary123; name = userId
Content-Type: text/plain
1426373
You can set it as part of Content type
contentType("multipart/form-data; boundary=--MyBoundary")
I found out that auto-generated boundary is what I need and it's not displayed in Rest Assured log, but it's sent.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.