I have difficulties executing post request that is supposed to return csv file using unirest (mashape).
When I execute the request with postman I get status 200 and raw response body contains following:
As soon as I click on save response and download it on my local file system I do not see the symbols in the downloaded file:
"Entity Type","TOTAL ACCOUNTS"
"ACC","25"
For my post request with unirest I am using .asBinary()
method for the HttpResponse
but it seems that the byte array contains the same symbols represented by empty space. Here is my method:
private void checkResponseBinary(HttpResponse<InputStream> response, int expectedStatusCode) {
Integer responseStatusCode = response.getStatus();
InputStream responseBody = response.getBody();
String body = "";
try {
body = IOUtils.toString(responseBody, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
if (responseStatusCode != expectedStatusCode) {
throw new RuntimeException(
"Actual response status code " + responseStatusCode + " is not equal to expected " +
expectedStatusCode
+ ". Body: " + responseBody);
}
}
At this point body
String variable contains this:
When I write this content to file it looks even worse. The empty spaces are replaced with NUL
:
I want the content of the csv file to look like the downloaded file from postman:
"Entity Type","TOTAL ACCOUNTS" "ACC","25"
question from:
https://stackoverflow.com/questions/66060982/unirest-mashape-post-request-with-binary-response-contains-special-symbols 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…