自定义函数模板和泛型排序函数的使用
2009-12-12 18:46
435 查看
Overview
Symbian cookies are stored in the http header collection like otherheader 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.
Symbian的cookie保存在http的header集中的,和其它的header信息一样,但是可以取值可能会有麻烦。企图收集他们的标准方法是返圆一个命名为"Set-cookie"的单独项,他的值是"Cookie".下面的代码片断展示了怎样从HTTP transaction中取多个cookie的办法。这个代码在S60 3版的FP1和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.
S60中实现存储cookie到Cookie管理组件的private文件夹中,如果第三方想要直接的访问这些cookie文件,那么他需要所有的文件权限。
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
相关文章推荐
- usort( )函数—使用用户自定义的比较函数对数组中的值进行排序
- PHP 使用用户自定义的比较函数对数组元素排序
- c++中优先队列的使用(自定义排序函数)
- 函数:使用函数模板,泛型引用,重载进行数据交换
- php usort 使用用户自定义的比较函数对二维数组中的值进行排序
- PHP 使用用户自定义的比较函数对数组中的值进行排序
- 自定义函数使用map排序
- 使用sort 和自定义比较函数对任意成员变量排序
- PHP usort 使用用户自定义的比较函数对数组中的值进行排序
- usort — 使用用户自定义的比较函数对数组中的值进行排序
- <STL初探>list节点为自定义类型,如何访问节点中变量和函数,如何使用list自带的排序
- vc中怎么使用SendMessage自定义消息函数
- 写function自定义函数时使用jquery
- Java中使用Collections.sort()方法对数字和字符串泛型的LIst进行排序
- c#自定义条件排序 可以使用中文条件 datagirdview
- 函数模板的使用,对数字,字符的排序,
- MySQL中文汉字转拼音的自定义函数和使用实例(首字的首字母)
- 使用C++标准库sort自定义比较函数导致死循环问题
- vc中怎么使用SendMessage自定义消息函数
- 泛型的使用语自定义泛型