Getting a cookie from HTTP response
| Wed, 2004-02-04 18:54 | |
|
|
Here is the part of HTTP header I received and need to read: Set-cookie: JSESSIONID=java.sun.com-b93ae%253A4021100a%253A8f52f5678875885; And here is source code I used to read from HTTP header: Code: _LIT8(KCookieField,"Set-Cookie"); where strP is StringPool and cookie is THTTPHdrVal object.TPtrC8 cookieFieldName((TUint8*)(&KCookieField)->Ptr(), (&KCookieField)->Size()); RStringF headerName = strP.OpenFStringL(cookieFieldName); int error = hdr.GetField(headerName, 0, cookie); And, after reading a field, the value stored in cookie variable is: "Cookie". Is there anobody who knows how to do this the right way? Thanks in advance! It is always nice to help out people that need help. |






Forum posts: 26
Please help me!
RStringPool strP = aTrans.Session().StringPool();
RHTTPHeaders hdr = resp.GetHeaderCollection();
THTTPHdrFieldIter it = hdr.Fields();
TBuf<KMaxHeaderNameLen> fieldName16;
TBuf<KMaxHeaderValueLen> fieldVal16;
RStringF fieldCokie = strP.StringF(HTTP::ESetCookie,RHTTPSession::GetTable());
THTTPHdrVal fieldVal;
THTTPHdrVal cookie;
if (hdr.GetField(fieldCokie,0,fieldVal) == KErrNone){
RStringF basic = strP.StringF(HTTP::ECookie,RHTTPSession::GetTable());
RStringF realm = strP.StringF(HTTP::ECookieValue,RHTTPSession::GetTable());
if ((fieldVal.StrF() == basic) &&
(!hdr.GetParam(fieldCokie, realm, cookie))){
RStringF realmValStr = strP.StringF(cookie.StrF());
cookieValue.Copy(realmValStr.DesC());
}
}
It is always nice to help out people that need help.
http://www.levi9.com/
http://levi9msnet.blogspot.com/
http://www.codeplex.com/aspnetlibrary
Forum posts: 3
Forum posts: 26
I solved that and it worked fine for Symbian 7. I didn't try that code on 3rd edition but I think it should work.
Here is the code I used:
RStringF cookieField = iSess.StringPool().StringF(HTTP::ECookie,RHTTPSession::GetTable());
TBuf8<200> tempBuff;
tempBuff.Append(_L8("JSESSIONID="));
int sLen = strlen(status.sessionId);
tempBuff.Append((const TUint8*)status.sessionId, sLen);
aHeaders.SetRawFieldL(cookieField, (const TDesC8&)tempBuff, _L8(";"));
cookieField.Close();
}
Where "status.sessionId" is char* holding the value that I needed to set as cookie's value.
I hope this will help you.
Regards,
Sasa
It is always nice to help out people that need help.
http://www.levi9.com/
http://levi9msnet.blogspot.com/
http://www.codeplex.com/aspnetlibrary
Forum posts: 3
In the code used to read cookie variable Cookieval how is declared?
thanks again
Forum posts: 26
In the code used to read cookie variable Cookieval how is declared?
thanks again
Hi kelem,
cookieValue was member variable in that class declared like this:
...
TBuf8<KMaxHeaderValueLen> cookieValue;
If you find my answers helpful you can always thank me by clicking on "[Applaud]" link next to my answers
Regards,
Sasa
It is always nice to help out people that need help.
http://www.levi9.com/
http://levi9msnet.blogspot.com/
http://www.codeplex.com/aspnetlibrary
Forum posts: 6
Thnx dude
U make my day using this post
THis post is quite helpful to me
Regards
Smit
Forum posts: 26
Hi smitesh,
I'm glad you found it useful. I spent quite some time on that so I thought I will probably save some else's time by posting that code.
Cheers,
Sasa
It is always nice to help out people that need help.
http://www.levi9.com/
http://levi9msnet.blogspot.com/
http://www.codeplex.com/aspnetlibrary
Forum posts: 2
hi Sasa,
Did you try to parse multi set-cookies from one HTTP header? I want to get the cookie value from one response header, but only the first set-cookie can be read out. Thanks.
Landing