Now I have a web server written with php. And there some php script files for database accessing. I'm writing a Qt app to send get/post request to the remote php scripts. However, it's not convenient to verify user identity for each request. So, I want to use session control on the web server. But I don't know how to do in Qt application.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
As Orangepill and PLB said, the solution is Passing cookies to the request url
, you may refer to QNetworkAccessManager::setCookieJar
.
Steps
- Instantiate the
QNetworkAccessManager
object and callsetCookieJar
for it. - Send POST request to the authenticate page which activates a session. Then you will have cookies got from the page in the
cookieJar
. - Send requests to the pages under the domain will with the session alive.