Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Series 60 2nd/3rd上处理HTTP通讯中302跳转的方法

From Wiki
Jump to: navigation, search
Article Metadata

beover1984 在 28 Aug 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

在使用Symbian提供的HTTP引擎时发现,在网络返回302跳转消息时获取跳转的URL为空(”Location”),这种情况在Series 60 2nd和3rd都存在。要解决这个问题需要首先了解一下HTTP引擎本身提供过滤机制(Filter),这种机制可以为实际应用中的各种HTTP消息响应机制提供支持,通过这个机制可以为HTTP引擎添加/删除某个过滤器,当然我们也可以实现自己的过滤器。之所以取到的跳转URL为空,就是因为HTTP引擎默认情况添加了302跳转的过滤器,如果程序中需要自己处理的话就需要把这个过滤器从当前的HTTP会话中删除掉,下面的代码演示了删除过滤器的方法:

void CHTTPEngine::ConstructL()
// Open RHTTPSession with default protocol ("HTTP/TCP")
TRAPD(err, iSession.OpenL());
if(err != KErrNone)
// Most common error; no access point configured, and session creation
// leaves with KErrNotFound.
"Cannot create session. Is internet access point configured?");
_LIT(KExitingApp, "Exiting app.");
CEikonEnv::Static()->InfoWinL(KErrMsg, KExitingApp);
//Remove the redirect filter.
RStringPool pool = iSession.StringPool();
iSession.FilterCollection().RemoveFilter( pool.StringF( HTTP::ERedirect, RHTTPSession::GetTable() ) );

使用上面的方法去掉HTTP会话中的跳转过滤后就可以正常响应和处理302跳转了。该代码在Series 60 2nd和3rd平台上测试通过。

This page was last modified on 15 December 2011, at 10:01.
68 page views in the last 30 days.