Symbian cookies are stored in the http header collection like other header information, but can be tricky to retrieve. Attempting to gather them the standard way returns a single item whose name is "Set-cookie" and whose value is "Cookie". The following code snippet shows how to get multiple cookies from an HTTP transaction. The code is tested with S60 3rd Edition FP1 and FP2.
The S60 implementation stores the cookie in a private folder of the Cookie Manager component. If a 3rd party wants to access these cookie files directly, AllFiles capability is required.
void loadFromTransaction(RHTTPTransaction& aTrans)
{
RHTTPResponse resp = aTrans.Response();
RStringPool strP = aTrans.Session().StringPool();
RHTTPHeaders headers = resp.GetHeaderCollection();
THTTPHdrFieldIter it = headers.Fields();
while (it.AtEnd() == EFalse)
{
RStringTokenF fieldName = it();
RStringF fieldNameStr = strP.StringF(fieldName);
THTTPHdrVal fieldVal;
if (headers.GetField(fieldNameStr, 0, fieldVal) == KErrNone)
{
RStringF wwwCookie = strP.StringF(HTTP::ESetCookie, RHTTPSession::GetTable());
if (fieldNameStr == wwwCookie)
{
RStringF nameValStr;
RStringF valueValStr;
// Check the cookie name and value
RStringF name = strP.StringF(HTTP::ECookieName, RHTTPSession::GetTable());
RStringF value = strP.StringF(HTTP::ECookieValue, RHTTPSession::GetTable());
TInt numCookies = headers.FieldPartsL(wwwCookie);
THTTPHdrVal nameVal, valueVal;
for (int i = 0; i < numCookies; i++)
{
string nameFromCookie = "", valueFromCookie = "";
if (headers.GetParam(wwwCookie, name, nameVal, i) == KErrNone)
{
RStringF strF;
RString str;
if (nameVal.Type() == THTTPHdrVal::KStrFVal)
{
strF = nameVal.StrF();
nameValStr = strP.StringF(strF); // this is the cookie's name
}
else if (nameVal.Type() == THTTPHdrVal::KStrVal)
{
str = nameVal.Str(); // this is the cookie's name
}
}
if (headers.GetParam(wwwCookie, value, valueVal, i) == KErrNone)
{
RStringF strF;
RString str;
if (valueVal.Type() == THTTPHdrVal::KStrFVal)
{
strF = valueVal.StrF();
valueValStr = strP.StringF(strF); // this is the cookie's value
}
else if (valueVal.Type() == THTTPHdrVal::KStrVal)
{
str = valueVal.Str(); // this is the cookie's value
}
}
/***
* do something with the name and value, such as storing them
* locally or in a file
***/
} // end for loop
}
}
++it;
} // end while
} // end loadFromTransaction
//==================
转自
http://wiki.forum.nokia.com/index.php/Reading_Multiple_Http_Cookies_using_Symbian_C%2B%2B