Aaaammm "No, it makes it QList<QVariant>............ (because it is not a QList<QVariant>)." ?
Aaaammm "No, it makes it QList<QVariant>............ (because it is not a QList<QVariant>)." ?
I suggest you rephrase this post because I have no idea what you mean. If it's that you don't see a difference between QVariant and QNetworkCookie then I suggest you click both links and read the docs to see the differences. You are trying to convert a QVariant holding a QList<QNetworkCookie> into QList<QVariant> which it is not thus you get an empty QList<QVariant>. It's like you wanted to convert a rectangle into a circle - you'd get an invalid circle because rectangles can't be converted to circles without actually knowing what a "rectangles" and "circles" are.
I didn't understand what he posted.... at firs he says that it's a QList<QVariant> and then in the brackets he says that it's not QList<QVariant>, but never mind that. I don't know how to convert it to a QList<QNetworkCookie> ? I guess not likeQt Code:
QList<QNetworkCookie> list = cookies.toList();To copy to clipboard, switch view to plain text mode
No, at first "he" says the cast tries to make it QList<QVariant>.
Yes, so "he" says.and then in the brackets he says that it's not QList<QVariant>,
Actually you should mind because it is the most important part of the whole discussion.but never mind that.
I guess the compiler already told you it is not the right route...I don't know how to convert it to a QList<QNetworkCookie> ? I guess not likeQt Code:
QList<QNetworkCookie> list = cookies.toList();To copy to clipboard, switch view to plain text mode
Try this:
Qt Code:
QList<QNetworkCookie> cookieList = qvariant_cast<QList<QNetworkCookie> >(cookies);To copy to clipboard, switch view to plain text mode
I don't know how to explain what happened...
My cookieList has 1 item: "d" wich is a QSharedDataPointer<QNetworkCookiePrivate> wich has another "d" wich is QNetworkCookiePrivate * with value 0x1 there is *d inside it wich is QNetworkCookiePrivate and insite that there is a QSharedData (commend,domain,expirationDate,httpOnly,name,path, secure,value) and they are all "not in scope"
You tried debugging a class your debugger has no support for. That's normal. Forget the debugger - after making the cast see the size of the list. If it is 0 then it's not a list but rather a QNetworkCookie object which would be strange. Try running this code (assuming "rep" is your QNetworkReply object):
Qt Code:
qDebug() << "Cookies set:" << var; QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(var); foreach(QNetworkCookie c, cookies){ }To copy to clipboard, switch view to plain text mode
Again it's only one cookie. The JSESSIONID.
Great, finally... Now you should check if setting multiple set-cookie headers is a valid policy with HTTP/1.1. If so then probably reporting a bug to Qt Software is a good idea. If not, then you have to find a workaround for the faulty server for instance using QNetworkReply::rawHeaderList() and QNetworkCookie::parseCookies().
From RFC 2109, "An origin server may include multiple Set-Cookie headers in a response. Note that an intervening gateway could fold multiple such headers into a single header."
Servers do return multiple Set-Cookie lines, for example (wrapping of line 10 is mine):Qt Code:
Resolving www.doubleclick.com... 216.73.93.8 Connecting to www.doubleclick.com|216.73.93.8|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Connection: keep-alive Date: Tue, 05 May 2009 08:43:11 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Set-Cookie: ecm=user_id=0&isMembershipUser=0&site_id=&username=&new_site=/ &unique_id=0&site_preview=0&langvalue=0&DefaultLanguage=1033&NavLanguage=1033& LastValidLanguageID=1033&ContType=&UserCulture=1033&SiteLanguage=1033; path=/ Set-Cookie: ASP.NET_SessionId=arv3wz3p3eqaayff0d1duv45; path=/; HttpOnly Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 30533 Length: 30533 (30K) [text/html]To copy to clipboard, switch view to plain text mode
I sent a bug report to QT. QNetworkReply::rawHeaderList() tells me that there is only one Set-Cookie ..... I think it is affected too. Can I dump the header to a QByteArray and cut the part I don't need ?
You can dump whatever you want wherever you want if there is an API call for that. Unfortunately I don't see means to do that in the API.
Anyone having other ideas ?
You can use QHttp or even QTcpSocket or implement a workaround in Qt itself.
For anyone having the same issue this problem is fixed in QT 4.5.2 and UP.
Thanks ChrisW67, and wysota.
Bookmarks