[英]Restassured Parse Body response with boundary
I use RestAssured, and I'm trying to download files with de GET call. 我使用RestAssured,并且尝试通过de GET调用下载文件。
My issue is that the request body is organised with a boundary. 我的问题是请求主体是有边界的。
So the file I get contain too many informations and is not usable. 因此我得到的文件包含太多信息,无法使用。 Here is an exemple of content of a simple text file downloaded :
这是一个下载的简单文本文件的内容示例:
--a8f82a89-d9c2-4fcb-a612-06e286bfcf66 Content-Disposition: form-data;
--a8f82a89-d9c2-4fcb-a612-06e286bfcf66 Content-Disposition:表单数据; name="metadata";
NAME = “元数据”; filename="metadata" Content-Type: application/json {"name":"Fichier_de_calcul.txt","id":{"metadata":{"deleted":false,"ephemeral":false,"synthesised":true,"systemOwned":true,"readOnly":false,"synchronisable":true,"createdOn":"2018-11-09T15:36:39Z","enabled":true,"lastModifiedOn":"2018-11-09T15:36:40.444Z"},"value":{"@type":"CoreKit.UUIDKey","value":"4de39a67-0075-4232-a236-09ab8d10aed9"}}} --a8f82a89-d9c2-4fcb-a612-06e286bfcf66 Content-Disposition: form-data;
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="@type";
NAME = “@类型”; filename="@type" Content-Type: text/plain CoreKit.FileMetadataAndFile --a8f82a89-d9c2-4fcb-a612-06e286bfcf66 Content-Disposition: form-data;
filename =“ @ type” Content-Type:文本/纯文本CoreKit.FileMetadataAndFile --a8f82a89-d9c2-4fcb-a612-06e286bfcf66 Content-Disposition:表单数据; name="file";
NAME = “文件”; filename="file" Content-Type: application/octet-stream 2 4 6 8 10 --a8f82a89-d9c2-4fcb-a612-06e286bfcf66--
filename =“ file”内容类型:application / octet-stream 2 4 6 8 10 --a8f82a89-d9c2-4fcb-a612-06e286bfcf66--
And here is the code I used to get this file : 这是我用来获取该文件的代码:
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();
}
Does someone know how I can do to : 有人知道我该怎么做:
Parse the body (I'd like to get the "filename" parameter) Create the downloaded file based on the "application/octet-stream" part. 解析正文(我想获取“ filename”参数)基于“ application / octet-stream”部分创建下载的文件。
Thank you =) 谢谢=)
Can you please try below appraoch: you can set all header which you have and get request with your url. 您可以在下面的方法中尝试一下:您可以设置所有标头,并使用您的网址获取请求。
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.