PDA

View Full Version : QHttp download file problem.



fengtian.we
3rd June 2007, 12:22
#include <QApplication>
#include <QHttp>
#include <QUrl>
#include <QFileInfo>
#include <QFile>
#include <QtDebug>

class QHttp;

int main(int argc,char *argv[])
{
QApplication qapp(argc,argv);
QHttp *http;
http=new QHttp();
QUrl *url=new QUrl("http://feymercurial.com/forum/profile.php?mode=viewprofile&u=873");

QFileInfo fileinfo(url->path());


QFile *file = new QFile(fileinfo.fileName());
file->open(QIODevice::WriteOnly);

http->setHost(url->host(),80);
int httpGetId=http->get(url->path(),file);
qDebug() << httpGetId;

return qapp.exec();
}

--------------------------------
:confused:

QUrl *url=new QUrl("http://feymercurial.com/forum/profile.php?mode=viewprofile&u=873");
file profile.php is empty.

but if : QUrl *url=new QUrl("http://www.a2gold.com/index_en.php");

the file index_en.php is have content.

why?

wysota
3rd June 2007, 12:29
Are you implementing some spam related software?

fengtian.we
3rd June 2007, 12:43
NO NO~ haha~

:) my Boss will salesmanship some our product, so let me find MSN number~

our product is about game WOW.

I think this not spam related software :)

fengtian.we
4th June 2007, 11:22
help me ~ please~

wysota
4th June 2007, 13:27
Start by moving that QUrl object to stack.Then connect to QHttp signals that transmit information about the response header and display the header contents, it'll probably tell you something important (at least the status code).

fengtian.we
5th June 2007, 09:08
ok , let me try :)

fengtian.we
9th June 2007, 05:10
My case:
page with parameter can download:http://www.a2gold.com/index_en.php
page without parameter,can't download:http://feymercurial.com/forum/profile.php?mode=viewprofile&u=873


Code:


int main(int argc,char *argv[])
{
QApplication qapp(argc,argv);
QHttp *http;
http=new QHttp();

//QUrl *url=new QUrl("http://feymercurial.com/forum/profile.php?mode=viewprofile&u=873"); //this can't download.

QUrl *url=new QUrl("http://www.a2gold.com/index_en.php"); //this can download.

QFileInfo fileinfo(url->path());


QFile *file = new QFile(fileinfo.fileName());
file->open(QIODevice::WriteOnly);

http->setHost(url->host(),80);
int httpGetId=http->get(url->path(),file);
qDebug() << httpGetId;

return qapp.exec();
}

how can i download a page with a parameter?

LMZ
9th June 2007, 14:35
Simply dont use path(), instead use text parsing, here is an example:

bool HttpGetFile::ParseUrl( const QString& qstrUrlIn, int& iError )
{
QString qstrUrl = qstrUrlIn;

QUrl qUrl( qstrUrl );

if( qstrUrlIn.length() == (qUrl.scheme().length() + 3 + qUrl.host().length()) )
{
qstrUrl += "/";
qUrl = qstrUrl;
}

if( !qUrl.isValid() )
{
iError = 8;
return false;
}

if( qUrl.scheme() != "http" )
{
iError = 9;
return false;
}

qstrHost = qUrl.host();
qstrPath = qstrUrl.remove( 0, 7 + qstrHost.length() );// 7 == http://

return true;
}

fengtian.we
11th June 2007, 09:49
??? what mean?

wysota
11th June 2007, 16:36
:) my Boss will salesmanship some our product, so let me find MSN number

What do you intend to do with those numbers? Because if you want to send them a message "hey, buy our great software", then that's spamming.

jacek
11th June 2007, 16:36
Please, don't start more than one thread on the same problem. Threads merged.

fengtian.we
12th June 2007, 10:28
my boss sell the WOW(online game) gold :)

wysota
12th June 2007, 10:39
This doesn't answer my question.