[英]Restassured Parse Body response with boundary
我使用RestAssured,并且尝试通过de GET调用下载文件。
我的问题是请求主体是有边界的。
因此我得到的文件包含太多信息,无法使用。 这是一个下载的简单文本文件的内容示例:
--a8f82a89-d9c2-4fcb-a612-06e286bfcf66 Content-Disposition:表单数据; NAME = “元数据”; filename =“ metadata”内容类型:application / json {“ name”:“ Fichier_de_calcul.txt”,“ id”:{“ metadata”:{“ deleted”:false,“ ephemeral”:false,“ synthesized”:true “systemOwned”:真实的, “readOnly的”:假的, “synchronisable”:真实的, “createdOn”: “2018-11-09T15:36:39Z”, “已启用”:真实的, “lastModifiedOn”:“2018-11- 09T15:36:40.444Z“},” value“:{” @ type“:” CoreKit.UUIDKey“,” value“:” 4de39a67-0075-4232-a236-09ab8d10aed9“}}} --a8f82a89-d9c2-4fcb -a612-06e286bfcf66内容处置:表格数据; NAME = “@类型”; filename =“ @ type” Content-Type:文本/纯文本CoreKit.FileMetadataAndFile --a8f82a89-d9c2-4fcb-a612-06e286bfcf66 Content-Disposition:表单数据; NAME = “文件”; filename =“ file”内容类型:application / octet-stream 2 4 6 8 10 --a8f82a89-d9c2-4fcb-a612-06e286bfcf66--
这是我用来获取该文件的代码:
Response resp = RestAssured.given().headers(headers).get(url);
byte[] fileContent = resp.body().asByteArray();
File fileToSave = new File(classPath);
try {
Files.write(fileContent, fileToSave);
} catch (IOException e1) {
e1.printStackTrace();
}
有人知道我该怎么做:
解析正文(我想获取“ filename”参数)基于“ application / octet-stream”部分创建下载的文件。
谢谢=)
您可以在下面的方法中尝试一下:您可以设置所有标头,并使用您的网址获取请求。
Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();
String finaleNAme=response.jsonPath().get("jsonValuewhichyouwanttoget");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.