Qt - webkit - how to login programmatically

2020-06-06 02:43发布

I am making a web scraper. In that I need to login into my email account programatically. Can anybody say how to achieve that. I think "QNetworkAccesManager" and it's "get()" can make this. But, I don't know exactly. Somebody please shed a light on this issue.

Note: I am using Qt-4.7.2 + C++

1条回答
我只想做你的唯一
2楼-- · 2020-06-06 03:16

If the login is done in a web page then you should perform a post operation using QNetworkAccessManager::post() including the login fields in the data.

For instance:

QNetworkAccessManager network;
QByteArray loginData("user=myName&password=myPassword");
QNetworkRequest request(QUrl("http://mySite.com/login"));
QNetworkReply* pReply(network.post(request, loginData);

If the login is done via HTTP authentication method then you should connect the signal QNetworkAccessManager::authenticationRequired to one slot and fill the authentication data there.

查看更多
登录 后发表回答