Get metadata

Jul 12, 2013 at 10:25 PM
HI,
 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.
Coordinator
Jul 15, 2013 at 4: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.

Steve
Jul 15, 2013 at 5: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"https://os-keystone01.servosity.com.lab:5000/v2.0/tokens");
    request1.set_method(methods::HEAD);
request1.headers().add(L"Content-type", L"application/json");
request1.set_body(authData);
auto responseTask1 = client->request(request1);
http_response response1;
response1 = responseTask1.get();
std::wcout<<response1.to_string()<<std::endl;
but i cannot figure out why the same code is not working with HEAD?
Can you suggest any corrections in it.

Akshat
Coordinator
Jul 15, 2013 at 5: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.

Thanks,
Steve
Jul 15, 2013 at 5:53 PM
Steve,
 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.