Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Download a file from URL have space
I can't download a file from URL have space or %20
I test ' ' , '%20' , '+' but i can't download
@ARASHz4 Show the code you are using to download the file.. specifically the part that makes the URL so we can see what's wrong.
this my code for download file
DownloadManager = new QNetworkAccessManager(this); reply = DownloadManager->get(QNetworkRequest(Url));
Url is text a lineEdit
You should also show the code you are using to create the
@ARASHz4 Well if you look here http://doc.qt.io/qt-5/qurl.html#QUrl-2 you will see that QUrl will handle spaces for you. So that is weird that it isn't working because QNetworkRequest will turn your text QString into a QUrl automatically.
So a thing you could do to test is make the QUrl yourself like so:
QUrl myUrl(Url); Q_ASSERT(myUrl.isValid()); reply = DownloadManager->get(QNetworkRequest(myUrl));
If that shows it is valid, you could try making it more strict with:
QUrl myUrl(Url, QUrl::StrictMode); Q_ASSERT(myUrl.isValid());
That second one should fail if there is a problem.
That should give you a better idea of if the url is valid or not.
I'd recommend taking a look at QUrl::fromUserInput which looks to be more appropriate in your use case.
@ambershark i use QUrl:
QUrl murl = mystr;
this code work?
@SGaist i test this but no difference
Error is : server replied: Not Acceptable
Can you show what you are entering and what you URL is used to do your request ?
@SGaist I test this pic :
@ARASHz4 Did you try setting the QUrl to strict mode and see if it is valid?
That url should work just fine, so there must be some problem in how you are setting your url.
@ambershark yes is valid
Url = QUrl::fromUserInput(ui->addressLineEdit->text()); qDebug()<<Url.isValid();
return me true but i can't download this file!
@ARASHz4 I'll write a quick test app and see if it works for me..
The problem is not the URL. You are getting a 406 error.. Basically, the server tells you that your query is missing some stuff.
QNetworkRequest request(url); request.setRawHeader("Accept", "*/*"); request.setRawHeader("User-Agent", "name-of-your-application");
what doing this code?
request.setRawHeader("Accept", "*/*"); request.setRawHeader("User-Agent", "name-of-your-application");
It's setting the HTTP Accept (definition 14.1) and User-Agent (definition 14.43) header. See RFC2616.