我想发送一个 POST 请求,其中 -
在 Rest Assured Code 中,我可以使用以下代码以字符串格式获取静态 JSON 有效负载 -
String jsonFilePath = "<<Path to JSON File>>/Test_new.json";
String response = given().log().all().header("X-AUTH-TOKEN",res).body(new String(Files.readAllBytes(Paths.get(jsonFilePath)))).
when().post("<<POST RESOURCE URL>>").
then().log().body().assertThat().statusCode(200).extract().response().asString();
运行此代码时,仅使用静态 JSON 有效负载,我收到“415”错误代码。问题 -
您需要使用multiPart()
方法来上传文件,而不是body()
方法。例如:
File json = new File("src/test/resources/test_new.json");
File file = new File("src/test/resources/debug.log");
given().log().all()
.multiPart("files", file)
.multiPart("body", json, "application/json")
.post("your_url");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句