tags:

views:

140

answers:

2

When downloading a file using QNetworkAccessManager (Qt 4.5.2) is possible that the original URL redirects to a new one containing the real name of the file downloaded. How this file name can be read?

The answer should be QUrl QNetworkReply::url () const as the documentation says that: Note that the URL may be different from that of the original request.

Unfortunately it returns the original URL and not the new one.

Any idea?

A: 

Try getting it from the response header via:

QNetworkRequest::header(QNetworkRequest::LocationHeader)

The documenation states that QNetworkRequest::LocationHeader:

corresponds to the HTTP Location header and contains a URL representing the actual location of the data, including the destination URL in case of redirections.

QNetworkRequest::header documentation.

QNetworkRequest::LocationHeader documentation.

Karl Voigtland
Empty header :( ... the rawHeader works OK.
Das
A: 

You'll have to parse Content-Disposition header (reply->rawHeader("Content-Disposition")) manually in order to get filename from it.

gonzo
Yes, it works. Returns the name of the file as:attachment; filename="afile.zip"Thanks !
Das