Getting a cookie from HTTP response
Login to reply to this topic.
Wed, 2004-02-04 18:54
Joined: 2004-02-04
Forum posts: 26
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");
TPtrC8 cookieFieldName((TUint8*)(&KCookieField)->Ptr(), (&KCookieField)->Size());

RStringF headerName = strP.OpenFStringL(cookieFieldName);
int error = hdr.GetField(headerName, 0, cookie);
where strP is StringPool and cookie is THTTPHdrVal object.
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.
http://www.vegaitsourcing.rs
http://www.codeplex.com/aspnetlibrary


Thu, 2004-02-05 17:51
Joined: 2004-02-04
Forum posts: 26
I posted a code for reading a cookie from http header but still can't write a cookie. I can write anything accept "Cookie". When I write some value for "Cookie" field, after submiting the data, the "Cookie" field is clear.
Please help me!

Code:
RHTTPResponse resp = aTrans.Response();
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.vegaitsourcing.rs
http://www.codeplex.com/aspnetlibrary

Sat, 2007-03-03 13:25
Joined: 2007-03-01
Forum posts: 3
have you solved it?Work on 3rd edition?
Sat, 2007-03-03 18:38
Joined: 2004-02-04
Forum posts: 26
Hello kelem,

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:

Code:
void CNetwork::SetCookie(RHTTPHeaders aHeaders){
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.vegaitsourcing.rs
http://www.codeplex.com/aspnetlibrary

Sat, 2007-03-03 20:38
Joined: 2007-03-01
Forum posts: 3
Thank you very much for answer.

In the code used to read cookie variable Cookieval how is declared?
thanks again


Sun, 2007-03-04 16:49
Joined: 2004-02-04
Forum posts: 26
Quote from: kelem
Thank you very much for answer.

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:

Code:
#define KMaxHeaderValueLen 128

...

TBuf8<KMaxHeaderValueLen> cookieValue;

If you find my answers helpful you can always thank me by clicking on "[Applaud]" link next to my answers Wink

Regards,
Sasa

It is always nice to help out people that need help.
http://www.vegaitsourcing.rs
http://www.codeplex.com/aspnetlibrary

Tue, 2008-02-19 13:08
Joined: 2005-11-18
Forum posts: 6

Thnx dude
U make my day using this post
THis post is quite helpful to me
Regards
Smit

Tue, 2008-02-19 13:40
Joined: 2004-02-04
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.vegaitsourcing.rs
http://www.codeplex.com/aspnetlibrary

Tue, 2008-06-24 15:57
Joined: 2008-05-30
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


copyright 2003-2009 NewLC SARL