如何在Qt应用程序中保存http会话 [英] How to save the http session in qt application

查看:237
本文介绍了如何在Qt应用程序中保存http会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有一个用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.

  1. 实例化QNetworkAccessManager对象并为其调用setCookieJar.
  2. 将POST请求发送到激活会话的身份验证页面.然后,您将从cookieJar页面中获得cookie.
  3. 将请求发送到域下的页面将使会话保持活动状态.
  1. Instantiate the QNetworkAccessManager object and call setCookieJar for it.
  2. Send POST request to the authenticate page which activates a session. Then you will have cookies got from the page in the cookieJar.
  3. Send requests to the pages under the domain will with the session alive.

这篇关于如何在Qt应用程序中保存http会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆