如何使用 Qt 下载 csv 文件(在 __dopostback 之后)
Posted
技术标签:
【中文标题】如何使用 Qt 下载 csv 文件(在 __dopostback 之后)【英文标题】:How to download a csv file (behind a __dopostback) with Qt 【发布时间】:2011-04-16 17:00:17 【问题描述】:我需要一个函数来从“会议结果”中下载 csv 文件: http://www.rwwa.com.au/cris/meetingdownload.aspx?meeting=15014
问题是你需要点击“会议结果”链接来获取文件。
此链接具有以下关联 URL: javascript:__doPostBack('ctl00$ContentPlaceHolderMain$linkButtonResults','')
Qt中如何模拟点击下载文件?
注意:我检查了 Qt 中的 HTTP 示例,但由于 csv 文件没有直接链接,我不知道如何下载它。
感谢大家的时间和回答。 最好的问候
【问题讨论】:
【参考方案1】:也就是说,用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,以及我是否遵循了好的方法。
【讨论】:
以上是关于如何使用 Qt 下载 csv 文件(在 __dopostback 之后)的主要内容,如果未能解决你的问题,请参考以下文章