login about faq

Background: I need to get the attachment filename provided by the http response while using the CkHttp Download() method. There does not seem to be an integrated method for that specifically and that is just fine since it may be always be provided in the response.

Problem: After downloading the file I can call get_LastResponseHeader() or one of the similar methods, so that I can parse the response header. However I am not able to get the header as a CkHttpResponse object or even initialize a new CkHttpResponse object from the string returned by get_LastResponseHeader().

Request: The reason for me to want to retrieve the response as a CkHttpResponse object is that CkHttpResponse has built-in methods for working with the individual headers in the response. I could manually parse the response string and simply look for the attachment header, but my request would seem like a more elegant solution.

Alternative: In case I have missed something here, please let me know. Maybe I should not even use the Download() method here, but HttpSynchronousRequest() instead.

asked Jan 07 '15 at 09:08

roan98dk's gravatar image


HTTP requests and responses are MIME. You can load the LastResponseHeader string into a CkMime object, and then use CkMime's API to get the contents of the header fields, as well as attributes within structured header fields. It shouldn't matter that the MIME you're loading into the CkMime object is bodyless -- it will still load and parse the header..


answered Jan 07 '15 at 21:42

chilkat's gravatar image

chilkat ♦♦

Thanks, it works perfectly with the following code (for future reference):

CkMime mime;
const char *fileName = mime.getHeaderFieldAttribute("Content-Disposition", "filename");

I am happy to see that it is case-insensitive :-)


answered Jan 08 '15 at 07:46

roan98dk's gravatar image


Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Jan 07 '15 at 09:08

Seen: 2,177 times

Last updated: Jan 08 '15 at 07:46

powered by OSQA