I’m sorry for asking this question here. I’m confused. I used curl to remotely download a .tar.gz file successfully. However, when I try to use the REST API method to connect to the website, an error occurs and the content cannot be decoded or displayed.
Here are some parts of my code and the results:
I can download the tar.gz file successfully via the IP path and obtain the data use this command
curl -k http://192.x.x.x/LogServices/DiagLogs/Entries/20/attachment >/tmp/attachment.tar.gz
or
curl -k http://192.x.x.x/LogServices/DiagLogs/Entries/20/attachment -o /tmp/attachment.tar.gz
However, I encountered a failure when trying to download it via the REST API on the web.
And using “cat” command the result is as follows:
enter image description here
use “tar -xf file”command the result is as follows:
enter image description here
std::string Name = "LogServices/DiagLogs/Entries/"+entryID+"/attachment";
std::string file_name = "attachment.tar.gz";
std::string curl_cmd = "curl -k -L " IP_addr + Name;
std::string res = execCurl(curl_cmd.c_str());
asyncResp->res.jsonValue["curl_cmd"] = curl_cmd;
if(res.empty()){
asyncResp->res.jsonValue["message"] = "res empty.";
return;
}
//asyncResp->res.addHeader("Content-Type", "application/x-tar");
asyncResp->res.addHeader(boost::beast::http::field::content_type,
"application/gzip");
asyncResp->res.addHeader("content_disposition", "attachment; filename="" + file_name + """);
// Configure this to be a file download when accessed
// from a browser
asyncResp->res.body() = std::move(res);
Hong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.