如何使用Qt下载csv文件(在__dopostback后面)

时间:2011-04-16 17:00:17

标签: qt qt4 qnetworkaccessmanager dopostback

我需要一个从“会议结果”中下载csv文件的功能: http://www.rwwa.com.au/cris/meetingdownload.aspx?meeting=15014

问题是您需要点击“会议结果”链接才能获取该文件。

此链接包含以下相关网址: 的javascript:__ doPostBack( 'ctl00 $ $ ContentPlaceHolderMain linkBut​​tonResults', '')

如何模拟点击以在Qt中下载文件?

注意:我从Qt检查了HTTP示例,但由于csv文件没有直接链接,我不知道如何下载它。

谢谢大家的时间和答案。 最好的问候

1 个答案:

答案 0 :(得分:0)

换句话说,使用WireShark获取的HTTP是(下面的Qt代码):

POST /cris/meetingdownload.aspx?meeting=15016 HTTP/1.1
Host: www.rwwa.com.au
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://www.rwwa.com.au/cris/meetingdownload.aspx?meeting=15016
Cookie: __utma=125158281.121279034.1302968401.1303017966.1303024785.5; __utmz=125158281.1302968401.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); rwwa_home=SID-4E7CCEFA-2D53D8FE; JSESSIONID=C7C7911A58DF8F12AAF4B426BD347520; __utmc=125158281
Content-Type: application/x-www-form-urlencoded
Content-Length: 557

__EVENTTARGET=ctl00%24ContentPlaceHolderMain%24linkButtonResults&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKLTI3Njg4NTg5OA9kFgJmD2QWBAIDDxYCHgRUZXh0BSUNCjwhLS1XUzogVlRBQjIzMEM7IEFTOiBWVEFCMjIwQy0tPg0KZAIFD2QWAgIBD2QWDAIBDw8WAh8ABR5DUklTOiBNZWV0aW5nIERvd25sb2FkIE9wdGlvbnNkZAIDD2QWAmYPFgIeB1Zpc2libGVoZAIFDw8WAh8ABSVQSU5KQVJSQSBSQUNFIENMVUIsIFN1bmRheSAxNy8wNC8yMDExZGQCBw8PFgIfAAUSKGF0IFBJTkpBUlJBIFBBUkspZGQCCQ8WAh8BaGQCDQ8WAh8BaBYCAgMPFgIfAWhkZFF%2Fdlkb2PzfgrCf7N5ngJjqeu9J&__EVENTVALIDATION=%2FwEWBALHkpPICQLq6ujxCAKu74e8CgLbgNGWDhGwePSQniauH%2Bus3CWjmz0dBm4v

我在Qt写下面的代码:

QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
        this, SLOT(replyFinished(QNetworkReply*)));

QNetworkRequest request;
request.setUrl(QUrl("http://www.rwwa.com.au/cris/meetingdownload.aspx?meeting=15016"));
request.setRawHeader("Host", "www.rwwa.com.au");
request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16");
request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
request.setRawHeader("Accept-Language", "en-us,en;q=0.5");
request.setRawHeader("Accept-Encoding", "gzip,deflate");
request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
request.setRawHeader("Keep-Alive", "115");
request.setRawHeader("Connection", "keep-alive");
request.setRawHeader("Referer", "http://www.rwwa.com.au/cris/meetingdownload.aspx?meeting=15016");
//request.setRawHeader("Cookie", "");
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRawHeader("Content-Length", "557");

reply = manager->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
        this, SLOT(slotError(QNetworkReply::NetworkError)));

但我不知道如何处理EVENTTARGET和VIEWSTATE,以及我是否遵循了良好的方法。