Cookies 格温:如何阅读饼干

Cookies 格温:如何阅读饼干,cookies,g-wan,Cookies,G Wan,我正在尝试读取cookies,但下面的脚本返回一个空字符串 http_t *http = (http_t*)get_env(argv, HTTP_HEADERS); xbuf_t *read_buf = (xbuf_t*)get_env(argv, READ_XBUF); char *p = read_buf->ptr; char *cookies = http->h_cookies ? p + http->h_cookies : 0; xbuf_xcat(reply, "

我正在尝试读取cookies,但下面的脚本返回一个空字符串

http_t *http =  (http_t*)get_env(argv, HTTP_HEADERS);
xbuf_t *read_buf  = (xbuf_t*)get_env(argv, READ_XBUF);
char *p = read_buf->ptr;
char *cookies = http->h_cookies ? p + http->h_cookies : 0;
xbuf_xcat(reply, "<HR>COOKIES [%s]<br>", cookies);
http_t*http=(http_t*)get_env(argv,http_头);
xbuf_t*read_buf=(xbuf_t*)get_env(argv,read_xbuf);
char*p=read_buf->ptr;
char*cookies=http->h\u cookies?p+http->h_cookies:0;
xbuf_xcat(回复,“
COOKIES[%s]
”,COOKIES);
我以前使用:http_头(我可以在chrome的控制台中看到)设置了一个cookie

那我怎么读饼干呢

谢谢你的回答


我使用的是GWAN 4.11.20

v4.11发布时没有同步
GWAN/includes
头,尽管添加了新值

因此,G-WAN脚本中
get_env()
使用的某些值与G-WAN使用的值不匹配

解决方案是更正
gwan.h
标题中的这些值。另一种更简单的访问cookie的方法是使用(请参阅“连接处理程序”选项卡)到达读取缓冲区,然后使用类似于G-WAN示例的代码查找cookie

Paulo,一位G-WAN用户也有同样的问题,他向我们发送了以下源代码:

int getSessionID(int argc, char *argv[]) {
    http_t *http = (http_t*)get_env(argv, HTTP_HEADERS);
    xbuf_t *read_buf = (xbuf_t*)get_env(argv, READ_XBUF);
    char *p = read_buf->ptr;
    int sessionID = 0;
    if (http) {
        sessionID = http->session_id;
fprintf(stderr, "Get SessionID %d\n", sessionID);        
    }

fprintf(stderr, "Get SessionID Cookie %d\n", http->h_cookies); 

    if (p && *p && http->h_cookies) {
        char *cookies = p + http->h_cookies;
fprintf(stderr, "Get SessionID Cookie %s\n", cookies);
        // The sessionID is on the Cookie
        sessionID = atoi(cookies + 5);
    }
    if (!sessionID) {
        // The sessionID is not on the Cookie so send the server Session_ID   
        sessionID = (int)get_env(argv, SESSION_ID);
    }
    if (!sessionID) {
        // Oops! I have no session from the Server. use the IP Address and a timestamp
        sessionID = (int)get_env(argv, REMOTE_BIN_ADDR) + getms();
    }
    return sessionID;
}

这将让您开始。

我为g-wan编写了简单库。你可以用它来做饼干。 示例代码:

char *val = gw_cookie(argv, "cookie_name=", 12);

链接:

您的库看起来不错,但GWAN 4.11.20似乎有问题。。。所以现在我在等待下一个版本:)我也在使用G-WAN 4.3.20,工作正常,但我还不能更新库。它需要c/c++脚本中的hiredis和“#pragma link”hiredis”行。