gSoap:如何在Qt中设置或更改客户端上的cookie?
我使用下一个代码通过服务在服务器上进行授权,并使用 cookie 标识符获取其他服务的方法进行授权。
TerminalControllerBinding soapObj;
soap_init1(soapObj.soap, SOAP_C_UTFSTRING);
soapObj.endpoint = "http://192.168.*.*/path/to/service";
ns1__getTemplatesResponse *response = new ns1__getTemplatesResponse;
std::string auth_res = "";
soapObj.ns1__auth("user", "password", auth_res);
QString sessid = QString::fromStdString(auth_res);
qDebug() << sessid;
soapObj.soap->cookies = soap_cookie(soapObj.soap, "sessid", sessid.toAscii().data(), ".");
服务器未获取 cookie“sessid”
I'am use next code for authorization on server by service, and get other service'methods using cookie identifer for authorizathion.
TerminalControllerBinding soapObj;
soap_init1(soapObj.soap, SOAP_C_UTFSTRING);
soapObj.endpoint = "http://192.168.*.*/path/to/service";
ns1__getTemplatesResponse *response = new ns1__getTemplatesResponse;
std::string auth_res = "";
soapObj.ns1__auth("user", "password", auth_res);
QString sessid = QString::fromStdString(auth_res);
qDebug() << sessid;
soapObj.soap->cookies = soap_cookie(soapObj.soap, "sessid", sessid.toAscii().data(), ".");
Server not getting cookie "sessid"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对您发布的代码感到有点困惑:您为 ns1__getTemplatesResponse 分配内存,然后做一些明显不相关的事情;事实上你根本就没有再引用它。此外,soap_cookie 是一个结构体,soap->cookies 基本上是一个列表。所以这里没有什么魔法可以将 cookie 传输到服务器。
我认为你想要的是soap_set_cookie。您可以在此处找到有关客户端 Cookie 的更多信息,但没有任何示例代码。然而,实际上更有用的是服务器端文档( cookie 的处理没有太大区别)。
另请注意,您需要使用
-DWITH_COOKIES
进行编译,或者在stdsoap.h
中自行定义宏(如果您尚未这样做)。I am kind of confused by the code you posted: You allocate memory for
ns1__getTemplatesResponse
, then do some apparently unrelated stuff; in fact you do not reference it again at all. Furthermoresoap_cookie
is a struct andsoap->cookies
is basically a list. So there is no magic that transfers the cookies to the server here.I think what you want is
soap_set_cookie
. You can find a little more information on client side cookies here, but there isn't any example code. Much more helpful however is actually the server side documentation (the handling of cookies doesn't differ much).Also notice that you either need to compile with
-DWITH_COOKIES
or define the macro yourself instdsoap.h
if you haven't done so already.