PDA

View Full Version : QHttp RFC Method PUT not work.



patrik08
18th May 2007, 14:57
From subjekt ....

If i Launch a Request PUT on http header not run! on QT4.3 beta
return only unknow error....

if i take my projekt ( http://sourceforge.net/projects/qt-webdav/ ) on qt4.2 can build and run ok on QT4.3beta can compile & run ... but can not upload file on method PUT..

RFC Standard are GET,POST,PUT,OPTIONS,HEAD,DELETE
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

Upload file on PUT having more speed as POST.......

QHttp::state() stay 0 QHttp::Unconnected

Anybody know this as Bug? or you have a Answer?




int main(int argc, char* argv[])
{
QApplication app(argc, argv);
qDebug() << "### start main ";
PutSender *job = new PutSender(QUrl("http://www.qtcentre.org/"),"a.zip");
return app.exec();
}



Method PUT Upload ....





#ifndef BASE_BUTTON_H
#define BASE_BUTTON_H

#include <QString>
#include <QDebug>
#include <QObject>
#include <QHttp>
#include <QAbstractSocket>
#include <QFileInfo>
#include <QHttp>
#include <QUrl>
#include <QtGui>
#include <QTimer>


#if defined Q_WS_MAC
#define WEBAGENTNAME "Mac QT4 / PPK_W @ciz.ch"
#endif
#if defined Q_WS_WIN
#define WEBAGENTNAME "Windows QT4 / PPK_W @ciz.ch"
#endif
#if defined Q_WS_X11
#define WEBAGENTNAME "Unix QT4 / PPK_W @ciz.ch"
#endif
typedef QMap<int, QStringList> cookiepam; /* cookie */
typedef QMap<QString, QString> ParamVar; /* xml params store */

class PutSender : public QObject
{
Q_OBJECT
/* #####################url#############uploadfiel### ####*/
public: PutSender( QUrl urigo , QString locfile )
{
urigoup = QUrl(urigo);
davinfo = new QHttp();
BeamUp = new QFile(locfile); /* upload file */

if (BeamUp->exists()) {
//////byteArray.clear();
//////BeamLog = new QBuffer(); /* buffer */
//////BeamLog->setBuffer(&byteArray);
////////BeamLog->open(QIODevice::ReadWrite);
logFile = new QFile("log.txt");
logFile->open(QIODevice::ReadWrite);
BeamUp = new QFile(locfile);
BeamUp->open(QIODevice::ReadOnly);
QHttpRequestHeader header("PUT", urigoup.path() ,1,1); /* header */
header.setValue("Host",urigoup.host());
header.setValue("User-Agent", WEBAGENTNAME );
header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
header.setValue("Accept-Language", "it,de-de;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2");
header.setValue("Connection", "keep-alive");
david = davinfo->request(header,BeamUp,logFile);
qDebug() << "### david " << david;
connect(davinfo, SIGNAL(dataSendProgress(int, int)), this, SLOT(SendStatus(int, int)));
connect(davinfo, SIGNAL(stateChanged(int)), this, SLOT(State(int)));
connect(davinfo, SIGNAL(requestStarted(int)), this, SLOT(Started(int)));
Debugme();

} else {
ErrorMSG("File upload not found!");
}
}
protected:
int david;
QUrl urigoup;
QHttp *davinfo;
QFile *BeamUp;
QFile *logFile;
QBuffer *BeamLog;
QByteArray byteArray;


private:
signals:
public slots:
void State( int a1 )
{
qDebug() << "### state " << a1;
}
void Started( int a1 )
{
qDebug() << "### strted " << a1;
}
void Debugme()
{
qDebug() << "### debug state 0/6 scala " << davinfo->state();
qDebug() << "### error " << davinfo->error();
QTimer::singleShot(1000, this, SLOT(Debugme()));
}

void SendStatus( int tot , int stats )
{
qDebug() << "### status " << tot << "-" << stats;
}
void ErrorMSG( const QString message )
{
qDebug() << "### message " << message;
}

};

#endif // BASE_BUTTON_H

wysota
18th May 2007, 18:03
Did you set the host in the QHttp object?

patrik08
18th May 2007, 21:04
Did you set the host in the QHttp object?

Yes original is it...

the same problem is on my source ...

http://sourceforge.net/project/showfiles.php?group_id=189894&package_id=222560

to build i downgrade to :

QMake version 2.01a
Using Qt version 4.2.3 in D:\qt\lib

the problem is only upload .. on qt4.3 beta ...
https://qt-webdav.svn.sourceforge.net/svnroot/qt-webdav/webdavdir/dav/davput.h

i not tested on http://labs.trolltech.com/blogs/2007/05/08/430-rc1-is-out/

Make yourself a free 5MB webdav account to test
https://www.sharemation.com/xythoswfs/webui?action=login&subaction=newuser
IMO: is not apache2 but header-responder comming...






class PutSender : public QObject
{
Q_OBJECT
/* #####################url#############uploadfiel### ####*/
public: PutSender( QUrl urigo , QString locfile )
{
urigoup = QUrl(urigo);
davinfo = new QHttp();
davinfo->setHost(urigoup.host(), 80);
BeamUp = new QFile(locfile); /* upload file */
starter = 0;

wysota
19th May 2007, 00:53
Could you provide a minimal compilable example reproducing the problem?

patrik08
19th May 2007, 15:44
Could you provide a minimal compilable example reproducing the problem?

Hurra sorry i found the bug on write && rewrite the minimal example on a single file main.cpp......

on QUrl correct is : QUrl("http://user:pass@www.sharemation.com/ppkciz/")

QUrl("http://user:pass@hostname.com/path/")


correct is...



QApplication app(argc, argv);
std::cout << "Main start Process ID:" << getpid() << std::endl;
/* User ID:" << getuid() unix */
/* Get Option from remote server */
HTTP_option *job = new HTTP_option(QUrl("http://user:pass@www.sharemation.com/ppkciz/"));



well on a other projekt i use :

mysql://user:pass@host:portnr/database to pass argument on main argv[] ....

and i replace qurl path ///

so QString dbase = dns.path().replace("/","");

to become the correct database name... als path...

i confused the path after whitout // on a copy & paste function

the QUrl is great to pass argument and scheme but must work exact!....







QUrl dns(mysqlshema);
QString dbase = dns.path().replace("/","");
QStringList drivers = QSqlDatabase::drivers();
if (!drivers.contains("QMYSQL")) {
std::cout << "### Load QMYSQL Driver Fail!." << std::endl;
return;
}

db0 = QSqlDatabase::addDatabase("QMYSQL");
db0.setHostName(dns.host());
db0.setDatabaseName(dbase);
db0.setUserName(dns.userName());
db0.setPassword(dns.password());

if (dns.port() > 0) {
db0.setPort(dns.port());
}

if (!db0.open()) {
...........