Can any body help me in identifying the type of the file i send in response to a POST request?
Actually, i have a REST API which needs to send a file zip file in response to a POST request. I can send back a message through response variable. I also found a way to send back a file in response (e.g. a zip file).
However i want to know, how can i identify the type of the file on client side (the one who will receive the response) and read the contents of the file (in this case zip file) and save it (as a zip file) ?
You should not be sending back a zip file in response to a POST request if the API is RESTful, as the verb is not idempotent and is reserved for creation.
Pedantry aside, if you are sending a file back, you will most likely have a header similar to this:
These headers allow you to force a download on the client side. Again, you should be doing a REST GET request or a Location redirect to another endpoint, as, by REST standards, a POST endpoint should not return anything but a location to the newly-created object.
Well, now i can send a zip file but on the receiving side i can not store it as a valid zip file. On receiving side i create a zip file and write contents to it by doing the following:
$response_body = substr($response, $header_size);
fwrite($zipfile, gzcompress($response_body));
Afterwards, when i open it with a zip software it tells that it is an invalid zip file. Any suggestion how should i store the contents of the zip file appropriately?