QtWebKit模块实现了HTML到DOM的解析,封装了Get等方法,直接使用

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

QtWebKit模块实现了HTML到DOM的解析,封装了Get等方法,直接使用就行了例:用代码实现在百度首页中输入关键字并提交,然后显示百度返回的搜索结果:
44.if(fileList.count() < 1)return;
45.
46. manager2 =new QNetworkAccessManager;
47.// QString fileName = "tootzoe.jpg";
48.QString newPathName ="newtootzoe.jpg";
49.
50.// foreach(QString fileName, fileList){
51.QString fileName = fileList.at(0);
52.file=new QFile(fileName);
53.if(!file->open(QFile::ReadOnly)){ qDebug() << "Error
opening file....";return ;}
54.
55.////===================================================
56.QByteArray formData;
57.QString _boundary ="-----------------------------
7d6bb34502ce";
58.QString contenttype ="multipart/form-data; boundary="+
_boundary;
59.
60. formData.append(QString("--"+ _boundary +"\r\n").toAscii());
61.//
62. formData.append(QString("Content-Disposition: form-data;
name=\"Filename\"\r\n\r\n").toUtf8());
63. formData.append(QString(fileName +"\r\n").toUtf8());
64. formData.append(QString("--"+ _boundary +"\r\n").toAscii());
// ASCII encoder
65.//////////
66. formData.append(QString("Content-Disposition: form-data;
name=\"RelPathName\"\r\n\r\n").toUtf8());
67. formData.append(QString(newPathName +"\r\n").toUtf8());
68. formData.append(QString("--"+ _boundary +"\r\n").toAscii());
// ASCII encoder
69.//////////
70. formData.append(QString("Content-Disposition: form-data;
name=\"sqlQuery\"\r\n\r\n").toUtf8());
71. formData.append(QString("FlashSentFileData\r\n").toUtf8());
72. formData.append(QString("--"+ _boundary +"\r\n").toAscii());
// ASCII encoder
73.//数据块 begin
74. formData.append(QString("Content-Disposition: form-data;
name=\"Filedata\"; filename=\""+ fileName +"\"\r\n").toUtf8());
75. formData.append(QString("Content-Type: application/octet-
stream\r\n\r\n").toUtf8());
76. formData.append( file->readAll());
77. formData.append(QString("\r\n").toAscii());
78.//数据块 end
79. formData.append(QString("--"+ _boundary +"--
\r\n").toAscii());
80.
81.
82. QNetworkRequest
request2(QUrl("http://localhost/console/uploadfile.aspx")) ;
83. request2.setHeader(QNetworkRequest::ContentTypeHeader,
contenttype);
84. request2.setHeader(QNetworkRequest::ContentLengthHeader,
formData.size());
85. reply2 = manager2->post(request2, formData);
86.connect(reply2, SIGNAL(finished()),
this,SLOT(uploadFileFinished()));
87. qDebug() << "uploading " << fileName;
88.
89.// }
90. file->close();
91.
92.}
93.
94.void uploadFileFinished()
95.{
96. qDebug() << "finished upload.... " << reply2-
>attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() ;
97. qDebug() << QString( reply2->readAll());
98.}
99.
100.
101.private:
102.QPushButton*uploadBtn;
103. QNetworkAccessManager *manager2;
104. QNetworkReply *reply2;
105.QFile*file;
106.
107.};
108.
109.int main(int argc, char**argv)
110.{
111.QApplication app(argc, argv);
112.
113. QNetworkAccessManager manager;
114. QNetworkRequest request;。

相关文档
最新文档