qnetworkaccessmanager

QNetworkAccessManager upload to local FTP server

自闭症网瘾萝莉.ら 提交于 2019-12-06 12:34:34
I can download from the server but I can't upload to it. It uploads the file but it's an empty file. This is basically what I'm doing: QString filename="Data.txt"; QFile file( filename ); file.open(QIODevice::ReadWrite); file.write("HELLO") ; QUrl urlup("ftp://127.0.0.1/file.txt"); urlup.setPassword("123"); urlup.setUserName("user"); urlup.setPort(21); QNetworkAccessManager *nam = new QNetworkAccessManager; QNetworkRequest requp(urlup); nam->put(requp,&file); file.close(); but it's not working; just uploads an empty file. user3220907 Instead of 127.0.0.1 use localhost Instead of setPort append

Qt QNetworkAccessManager and multiple QNetworkReply

匆匆过客 提交于 2019-12-06 11:20:05
问题 I have two get QNetworkRequest. I want to handle finished signals from different methods. For example this is code in MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); GetUserData(); connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(GetUserDataCompleted(QNetworkReply*))); GetMessages(); connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(GetMessagesCompleted(QNetworkReply*))); } This my one method I have tried replay-

Qt: connect a signal after a request is sent in QNetworkAccessManager [duplicate]

馋奶兔 提交于 2019-12-06 10:21:25
This question already has an answer here : Qt signal slot connection - QNetworkAccessManager (1 answer) Closed 4 years ago . I was checking some simple examples of using QNetworkAccessManager and I found this (Assuming that manager is a QNetworkAccessManager: QNetworkRequest request; request.setUrl(QUrl("http://www.someserver.com")); QNetworkReply *reply = manager->get(request); connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); connect(reply, SIGNAL(sslErrors(QList

How can I use Qt to get html code of the redirected page?

两盒软妹~` 提交于 2019-12-06 07:38:44
I'm trying to use Qt to download the html code from the following url: http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nucleotide&cmd=search&term=AB100362 this url will re-direct to www.ncbi.nlm.nih.gov/nuccore/27884304 I try to do it by following way, but I cannot get anything. it works for some webpage such as www.google.com, but not for this NCBI page. is there any way to get this page?? QNetworkReply::NetworkError downloadURL(const QUrl &url, QByteArray &data) { QNetworkAccessManager manager; QNetworkRequest request(url); QNetworkReply *reply = manager.get(request); QEventLoop loop;

Handling network timeout in Qt

霸气de小男生 提交于 2019-12-06 05:58:54
问题 When dealing with QNetworkReply , it is prescribed to use timers to abort the connection. Here is my current code: void ImageDownloader::download(QString imgUrl){ this->timeoutTimer = new QTimer(this); this->timeoutTimer->setSingleShot(true); this->timeoutTimer->setInterval(15000); connect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(timeout())); QUrl requestUrl(imgUrl); QNetworkRequest nwRequest(requestUrl); this->imageNwReply = this->nam->get(nwRequest); connect(imageNwReply,SIGNAL

QObject: Cannot create children for a parent that is in a different thread

淺唱寂寞╮ 提交于 2019-12-05 23:31:48
问题 EDIT: I tried doing what you guys told me in comments ... : Citizen * c = new Citizen(this); QThread thread; c->moveToThread(&thread); connect(&thread, SIGNAL(started()), c, SLOT(ProcessActions())); thread.start(); This produces even more errors: QThread: Destroyed while thread is still running ASSERT failure in QThread::setTerminationEnabled(): "Current thread was not started with QThread.", file c:\ndk_buildrepos\qt-desktop\src\corelib\thread\qthread_win.cpp, line 542 Invalid parameter

QNetworkAccessManager - How to send “PATCH” request

我们两清 提交于 2019-12-05 19:36:04
I am trying to send a "PATCH" request to my firebase application.As far as I read QNetworkManager doesn't support "Patch" request. How can I send "PATCH" request ? So we are clear that there is no method in QNetworkAccessManager named "patch" Therefore I have used "sendCustomRequest" but with QBuffer. Because QNetworkManager requires a QIODevice object. QString destination=""; currentNode.replace(QString("/").append(latestNode),""); destination .append(host) .append(currentNode) .append(".json"); QString jsonString=QString(QString("{").append("\"").append(latestNode).append("\"").append(":")

Method to reset the QNetworkAccessManager backend

旧街凉风 提交于 2019-12-05 12:41:49
It seems that QNetworkAccessManager does not handle missing files retrieved by ftp if the ftp server requires authentication. The situation is this: I'm downloading multiple files from the same ftp server that requires username and password. I successfully download a few files then send a GET for a file that does not exist. That request reports failure. I then send a GET request for a file that should be valid. That request never emits a finished signal or error. Qt 4.7.4 Please help! This is driving me nuts. I think that if I can somehow reset the ftp backend, this problem might be solvable.

Reading HTTP headers

做~自己de王妃 提交于 2019-12-04 20:38:10
I am trying to connect my application with a web service and here ,a user suggested to send custom headers back to my application. I am using this code void Coonnec::serviceRequestFinished(QNetworkReply *reply) { QByteArray bytes = reply->readAll(); if (reply->error() != QNetworkReply::NoError) { qDebug() << "Reply error: " + reply->errorString(); } else { qDebug() << "Uploaded: " + QDateTime::currentDateTime().toString(); qDebug() << reply->rawHeaderList(); } reply->close(); bytes.clear(); reply->deleteLater(); } from php i send this header header('XAppRequest-Status: complete'); When running

QNetworkRequest with ssl local certificate

好久不见. 提交于 2019-12-04 15:46:34
I need to exchange data with server which requires local certificate (.crt file). I try this: loginRequest = QNetworkRequest(QUrl("https://somesite.com/login")); QSslConfiguration sslConf = loginRequest.sslConfiguration(); QList<QSslCertificate> certs = QSslCertificate::fromPath(Preferences::certificatePath()); qDebug() << certs.first().issuerInfo(QSslCertificate::Organization); // prints name sslConf.setLocalCertificate(certs.first()); qDebug() << "is valid " << sslConf.localCertificate().isValid(); // true qDebug() << "is null " << sslConf.localCertificate().isNull(); // false qDebug() <<