quick-cocos2d-x cookie每次都改变的问题

来源:互联网 发布:centos rm rf 恢复 编辑:程序博客网 时间:2024/05/16 10:24

我使用的quick版本是3.2rc1版本

在lua代码中设置cookie的使用方法

local tr  = network.createHTTPRequest(onRequestFinished, completeUrl, method)

tr:setCookieString(cc.FileUtils:getInstance():getWritablePath()..'cookie.txt')

tr:start()

      按此方法设置之后发现每次返回的cookie列表是变化的

     原因如下:

libquick 的c++代码:

void HTTPRequest::setCookieString(const char *cookie)
{
      CCAssert(m_state == kCCHTTPRequestStateIdle, "HTTPRequest::setAcceptEncoding() - request not idle");
curl_easy_setopt(m_curl, CURLOPT_COOKIE, cookie ? cookie : ""))
}

修改为

void HTTPRequest::setCookieString(const char *cookie)
{
    CCAssert(m_state == kCCHTTPRequestStateIdle, "HTTPRequest::setAcceptEncoding() - request not idle");
    if (cookie) {
        if (CURLE_OK !=curl_easy_setopt(m_curl,CURLOPT_COOKIEFILE, cookie)) {
            printf("cookie enable failed");
        }
        if (CURLE_OK !=curl_easy_setopt(m_curl,CURLOPT_COOKIEJAR, cookie)) {
            printf("cookie enable failed");
        }
    }
}

这样就保证每次返回的cookie都一致了。

0 0