Get metadata

Jul 12, 2013 at 11:25 PM
 I am new to casablanca and I am trying to find a way to get the information of file as a response rather than getting the entire file. I have been trying to work with Http_client headers but could not really find out the way to get the information related to file on the server, like length of the file and other related data. Is there any way to do it?  Any help would be appreciated.
Thanks in advance.
Jul 15, 2013 at 5:40 PM
Hi akshat87,

Part of this depends on what information the server you are connecting to gives back in the response. The best thing you can do is to use the HTTP HEAD method. Basically it acts like the GET method retrieving all the HTTP headers but doesn't return the actual body in the response. To determine the length of the file you should be able to look at the Content-Length header. Use ::web::http::methods::HEAD.

Jul 15, 2013 at 6:16 PM
  Thank you for the prompt reply steve, I found that HEAD is the method i was looking for and written a code snippet too.
   Following is my code which works fine when i set the method to POST

    http_client *client = new http_client(L"");
request1.headers().add(L"Content-type", L"application/json");
auto responseTask1 = client->request(request1);
http_response response1;
response1 = responseTask1.get();
but i cannot figure out why the same code is not working with HEAD?
Can you suggest any corrections in it.

Jul 15, 2013 at 6:23 PM
Hi Akshat,

The HTTP HEAD, and GET method, are not for uploading data. Before you were talking about downloading a file, but the example code you have here is uploading a file. I'm confused now as to what you are trying to accomplish.

If you want to upload a new file then the PUT method is probably want you want. If you want to download a file, you can use HEAD first to examine the HTTP headers like Content-Length. Then you can use GET to actually retrieve the file, if desired.

Jul 15, 2013 at 6:53 PM
 Sorry as i got you confused.
Yes i want to download only,
And this is the code where i am posting my credentials to get back the authentication token.
this is not the place where i need to use HEAD. Will need it when i will start downloading the file. I just mixed two different things and got confused.

Thank you for the help. I appreciate it.