You can extract any component from the URI using
TUriC8::Extract()
, passing a
TUriComponent
flag for example, EUriQuery
or
EUriPath
.
The code fragment shows how to extract a scheme component. Parse the URI
before the component is extracted calling
TUriParser8::Parse()
.
_LIT8(KUri,"http://web.intra/Dev/Sysdoc/devlib.htm");
TUriParser8 parser;// Uri parser object
TInt result = parser.Parse(KUri);//parse the Uri descriptor
//Extract the scheme component from the parsed URI
const TDesC8& des = parser.Extract(EUriScheme);
where des
is a descriptor that contains the extracted scheme
component. Other components such as userinfo, host, port and so on defined in
TUriComponent
can be extracted in a similar way.
To retrieve a specific authority component from the URI, call
TAuthority8::Extract()
.
_LIT8(KAuthorityDesc, "http://user:[email protected]");
TAuthorityParser8 authorityParser; //authority parser object
authorityParser.Parse(KAuthorityDesc); //Parse the authority descriptor
const TDesC8& des = authorityParser.Extract(EAuthorityUserinfo); //extract the user info from the authority component
where, des
contains the user info that is extracted from the
authority component. EAuthorityUserinfo
is an enum value of
TAuthorityComponent
. Similarly, host and port can be
extracted using EAuthorityHost
and EAuthorityPort
respectively which are defined in TAuthorityComponent
.
To create a new descriptor containing the desired component or the full
URI, call TUriC8::DisplayFormL()
.
This converts a component into a new descriptor. The component to be
converted can take any value between EUriScheme
and
EUriFragment
or EUriComplete
(for the full URI). This
method is used to get a pointer to a 16 bit descriptor for GUI display of URI.
HBufC16* uri= parsedUri->DisplayFormL(EUriComplete);
where EUriComplete
indicates that all the components in the
URI are displayed.
To fetch the URI, call TUriC8::UriDes()
. This
returns a pointer to 8 bit descriptor(TDesC8
) containing
the URI, which is used for HTTP requests.
To create a new descriptor containing a specific component or the full
authority component, call TAuthority8::DisplayFormL()
.
This converts a component into a new descriptor. The component to be
converted can take any value between EAuthorityUserinfo
and
EAuthorityPort
or the full authority,
EAuthorityComplete
.
HBufC authority= parsedUri->DisplayFormL(EAuthorityComplete);
where EAuthorityComplete
means that the complete authority
is displayed.
For related information, see: