如何在Qt应用程序中保存http会话 [英] How to save the http session in qt application
问题描述
现在我有一个用php编写的Web服务器.还有一些用于数据库访问的php脚本文件.我正在编写一个Qt应用程序,以将get/post请求发送到远程php脚本.但是,为每个请求验证用户身份并不方便.因此,我想在Web服务器上使用会话控制.但是我不知道如何在Qt应用程序中做.
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.
推荐答案
正如Orangepill和PLB所说,解决方案是Passing cookies to the request url
,您可以参考QNetworkAccessManager::setCookieJar
.
As Orangepill and PLB said, the solution is Passing cookies to the request url
, you may refer to QNetworkAccessManager::setCookieJar
.
- 实例化
QNetworkAccessManager
对象并为其调用setCookieJar
.
- 将POST请求发送到激活会话的身份验证页面.然后,您将从
cookieJar
页面中获得cookie. - 将请求发送到域下的页面将使会话保持活动状态.
- 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.
这篇关于如何在Qt应用程序中保存http会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!