postman模拟:
具体请求代码:
File file = new File("src/test/resources/excelFile/地区收款导入.xls");
Map resFeedBackBodyMap = given().log().all()
.header("Security-Token", token)
.contentType("multipart/form-data")
.multiPart("file", file)
.when().post("/config/cityBankAccountConfig/upload.json")
.then().log().all().statusCode(HttpStatus.SC_OK)
.extract().body().as(Map.class);
注意点:
Excel文件需在本地新建再copy到工程中,如果直接在idea新建file,重命名为xls会报IOException
附:
官方文档:https://github.com/rest-assured/rest-assured/wiki/Usage#multi-part-form-data