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