简体   繁体   English

身份验证后从curl获取受保护的Cookie(C ++)

[英]Get Secured cookie from curl after authentication (c++)

How to get secured cookie from curl after authentication? 认证后如何从curl获取安全的cookie?

curl_easy_getinfo(curl_handler, CURLINFO_COOKIELIST, &cookies); curl_easy_getinfo(curl_handler,CURLINFO_COOKIELIST,&cookies); fetched only one cookie, the other secured cookie wasnt fetched. 仅获取了一个cookie,未获取其他安全的cookie。

Same with curl_easy_setopt(curl_handler, CURLOPT_COOKIEJAR, "cookie.txt"); 与curl_easy_setopt(curl_handler,CURLOPT_COOKIEJAR,“ cookie.txt”)相同;

However in java we could use cookie manager for login and after all the operations if we iterated the cookie manager there were two of them "Cookie" and "_WL_AUTHCOOKIE_JSESSIONID". 但是,在Java中,我们可以使用cookie管理器进行登录,并且在所有操作之后,如果我们对cookie管理器进行迭代,则其中有两个“ Cookie”和“ _WL_AUTHCOOKIE_JSESSIONID”。

In curl i am not able to fetch "_WL_AUTHCOOKIE_JSESSIONID" . 在curl中,我无法获取“ _WL_AUTHCOOKIE_JSESSIONID”。

Any help would be appreciated. 任何帮助,将不胜感激。

First, curl should get the same set of cookies that any other HTTP client gets. 首先,curl应该获得与任何其他HTTP客户端相同的cookie集。

Unfortunately, that is a should as servers sometimes act different depending on which client it thinks it speaks to and thus it may respond differently. 不幸的是,这是应该的,因为服务器有时会根据其认为与之交谈的客户端的行为而有所不同,因此响应可能会有所不同。 Also, since you're comparing with another client it is possible that the java version you see did some more HTTP requests that made it get the second cookie your curl request doesn't. 另外,由于您正在与另一个客户端进行比较,因此您看到的Java版本可能还会执行更多HTTP请求,从而使其获得了curl请求无法获得的第二个cookie。

To minimize the risk for all this, make sure the requests are as similar as possible so that the server cannot spot a difference between your clients and then it should repond identically and you will get the same set of cookies in both cases. 为了最大程度地降低所有风险,请确保请求尽可能相似,以使服务器无法识别出客户端之间的差异,然后服务器应以相同的方式进行响应,并且在两种情况下您将获得相同的cookie集。

When the curl based client gets both cookies, you can extract them fine with CURLINFO_COOKIELIST just as you want. 当基于curl的客户端同时获得两个cookie时,可以根据需要使用CURLINFO_COOKIELIST提取它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM