问题
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.
来源:https://stackoverflow.com/questions/17669978/how-to-save-the-http-session-in-qt-application