Download a file from URL have space
-
Hi
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.
-
@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.
@ambershark Hi
this my code for download fileDownloadManager = new QNetworkAccessManager(this); reply = DownloadManager->get(QNetworkRequest(Url));Url is text a lineEdit
-
Hi,
You should also show the code you are using to create the
QUrlobject. -
@ambershark Hi
this my code for download fileDownloadManager = new QNetworkAccessManager(this); reply = DownloadManager->get(QNetworkRequest(Url));Url is text a lineEdit
@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.
-
@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.
@ambershark i use QUrl:
QUrl murl = mystr;
this code work? -
I'd recommend taking a look at QUrl::fromUserInput which looks to be more appropriate in your use case.
-
Can you show what you are entering and what you URL is used to do your request ?
-
@SGaist I test this pic :
http://www.mlhsartgallery.org/DS10sem1/V_Boswell/dawn%20pic%204.bmp@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.
-
@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"); -
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");