Symbian3/SDK/Source/GUID-7800A00C-5BD3-46FA-9D0A-9DF29A5C057E.dita
changeset 0 89d6a7a84779
equal deleted inserted replaced
-1:000000000000 0:89d6a7a84779
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-7800A00C-5BD3-46FA-9D0A-9DF29A5C057E" xml:lang="en"><title>Specific
       
    13 header formats</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>This section describes the headers that have specific support for encoding
       
    15 or decoding using parts and parameters. Other headers not listed are encoded
       
    16 and decoded using a default mechanism that assumes the header field has a
       
    17 single part with a string value. </p>
       
    18 <section id="GUID-210B3CBF-2885-434C-A8DF-418D5A986088"><title>Accept</title> <p>This
       
    19 is a client request header. </p><codeblock id="GUID-1AB0D534-093B-5B81-A80D-D9002A5BA886" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
    20 // Setting a single media range with no parameter, i.e. Accept: text/html 
       
    21 RStringF textHtml = iStrTb.OpenFStringL(_L8("text/html")); 
       
    22 CleanupClosePushL(textHtml);
       
    23 THTTPHdrVal accVal(textHtml); 
       
    24 hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal); 
       
    25 CleanupStack::PopAndDestroy(&amp;textHtml);
       
    26 // Setting several media ranges with no parameters, i.e. Accept: text/html; text/vnd.wap.wml 
       
    27 RStringF textHtml = iStrTb.OpenFStringL(_L8("text/html")); 
       
    28 CleanupClosePushL(textHtml);
       
    29 RStringF textWml  = iStrTb.OpenFStringL(_L8("text/vnd.wap.wml")); 
       
    30 CleanupClosePushL(textWml);
       
    31 THTTPHdrVal accVal(textHtml);
       
    32 hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal); 
       
    33 accVal.SetStr(textWml); 
       
    34 hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal); 
       
    35 CleanupStack::PopAndDestroy(&amp;textHtml);
       
    36 CleanupStack::PopAndDestroy(&amp;textWml);
       
    37 // Setting a media range with a 'q' parameter,  Accept: text/html; q=0.8 
       
    38 RStringF textHtml  = iStrTb.OpenFStringL(_L8("text/html")); 
       
    39 CleanupClosePushL(textHtml);
       
    40 THTTPHdrVal accVal(textHtml); 
       
    41 THTTPHdrVal q(THTTPHdrVal::TQConv(0.8)); 
       
    42 hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal, iStrTb.String(HTTP::EQ,RHTTPSession::GetTable()), q); 
       
    43 CleanupStack::PopAndDestroy(&amp;textHtml);
       
    44 // Using an accept extension,  Accept: text/html; extended=value 
       
    45 RStringF textHtml  = iStrTb.OpenFStringL(_L8("text/html")); 
       
    46 CleanupClosePushL(textHtml);
       
    47 RStringF extended  = iStrTb.OpenFStringL(_L8("extended")); 
       
    48 CleanupClosePushL(extended);
       
    49 RStringF extendVal = iStrTb.OpenFStringL(_L8("value")); 
       
    50 CleanupClosePushL(extendVal);
       
    51 
       
    52 THTTPHdrVal accVal(textHtml); 
       
    53 THTTPHdrVal extVal(extendVal); 
       
    54 
       
    55 hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal, extended, extVal); 
       
    56 CleanupStack::PopAndDestroy(3); // textHtml, extended, extendVal</codeblock> 
       
    57    </section>
       
    58 <section id="GUID-37A82EFB-820A-4BD0-BA38-F3507F709E73"><title>Accept-Charset</title><p>This is a client request header. </p><codeblock id="GUID-EE14D9C1-1EEE-56FF-91F0-2B3BB8455A65" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
    59 // Setting up two accepted character sets, i.e.  Accept-Charset: us-ascii, utf-8 
       
    60 RStringF usAscii = iStrTb.OpenFStringL(_L8("us-ascii"));
       
    61 CleanupClosePushL(usAscii);
       
    62 RStringF utf8 = iStrTb.OpenFStringL(_L8("utf-8"));
       
    63 CleanupClosePushL(utf8);
       
    64 THTTPHdrVal accChSetVal(usAscii);
       
    65 hdr.SetFieldL(iStrTb.String(HTTP::EAcceptCharset,RHTTPSession::GetTable()), accChSetVal);
       
    66 // sets the first part accChSetVal.(SetStrutf8);
       
    67 hdr.SetFieldL(iStrTb.String(HTTP::EAcceptCharset,RHTTPSession::GetTable()), accChSetVal);
       
    68 // adds an additional part usAscii.Close();
       
    69 CleanupStack::PopAndDestroy(2);</codeblock></section>
       
    70 <section id="GUID-28FB5629-78CC-4229-B30D-6EF40F8E3C33"><title>Authorisation</title><p>This is a client request header. <b>Note:</b> The
       
    71 client need not set this header for most normal requests. </p><codeblock id="GUID-5D430FE4-8EE4-5537-818F-B7C9EBFC923D" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
    72 // Setting an authorization credential, i.e. Authorization: Basic c3ltYmlhbjpmMXN5bmNtbA== 
       
    73 RStringF basicCred = iStrTb.OpenFStringL(_L8("c3ltYmlhbjpmMXN5bmNtbA=="));
       
    74 CleanupClosePushL(basicCred);
       
    75 THTTPHdrVal authVal(iStrTb.String(HTTP::EBasic,RHTTPSession::GetTable()));
       
    76 hdr.SetFieldL(iStrTb.String(HTTP::EAuthorization,RHTTPSession::GetTable()), authVal);
       
    77 authVal.(SetStrbasicCred);
       
    78 hdr.SetFieldL(iStrTb.String(HTTP::EAuthorization,RHTTPSession::GetTable()), authVal);
       
    79 CleanupStack::PopAndDestroy(&amp;basicCred);</codeblock></section>
       
    80 <section id="GUID-64B95F8D-3E6D-48F6-A7E1-C997C69F5C6A"><title>Connection</title><p>This is a general header, that is, it
       
    81 applies to the connection between client and server. <b>Note:</b> The client
       
    82 need not set this header for normal, persistent HTTP/1.1 requests. </p><codeblock id="GUID-96A98445-2D81-555B-A727-CA364F906F04" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
    83 // Indicate that the connection is to close, i.e. Connection: close 
       
    84 THTTPHdrVal closeVal(iStrTb.String(HTTP::EClose,RHTTPSession::GetTable()));
       
    85 hdr.SetFieldL(iStrTb.String(HTTP::EConnection,RHTTPSession::GetTable()), closeVal);
       
    86 </codeblock></section>
       
    87 <section id="GUID-8F6F6A87-0C05-4635-BBCD-72B5E4AFB3CC"><title>Content-Length</title><p>This is an entity header, that is,
       
    88 it applies to the body present in a request or a response. <b>Note:</b> The
       
    89 client should not set this header for any request: it will be ignored. </p><codeblock id="GUID-58334818-7616-50EA-9862-2701610EB12D" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
    90 // Set a content length of 12345, i.e. Content-Length: 12345 
       
    91 THTTPHdrVal lengthVal(12345);
       
    92 hdr.SetFieldL(iStrTb.String(HTTP::EContentLength,RHTTPSession::GetTable()), lengthVal);
       
    93 </codeblock></section>
       
    94 <section id="GUID-6639232A-25C9-4CB6-9FF3-7F1EF3D8E148"><title>Content-Type</title><p>This is an entity header, that is,
       
    95 it applies to the body present in a request or a response. </p><codeblock id="GUID-8BCE3E31-E6A6-5908-AF87-A1CA6591D223" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
    96 // Set a content type of text/html, i.e. Content-Type: text/html 
       
    97 THTTPHdrVal contTypeVal(iStrTb.String(HTTP::ETextHtml,RHTTPSession::GetTable()));
       
    98 hdr.SetFieldL(iStrTb.String(HTTP::EContentType,RHTTPSession::GetTable()), contTypeVal);
       
    99 </codeblock></section>
       
   100 <section id="GUID-897C8418-2567-4739-8AFE-BE14A2FBC07D"><title>Date</title><p>This is a general header, that is, it applies
       
   101 to the connection between client and server. All three date formats specified
       
   102 in RFC2616 are supported in responses. Requests will be made using the RFC1123
       
   103 format only. </p><codeblock id="GUID-DE554314-FFAD-5807-B83E-70151BE366B0" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
   104 // Set a date of 9th August 2001, time 13:45:00.000, i.e. Date: Thu, 09 Aug 2001 13:45:00 GMT 
       
   105 THTTPHdrVal dateVal(TDateTime(2001, EAugust, 8, 13, 45, 0, 0));
       
   106 // note, the day starts at 0 
       
   107 hdr.SetFieldL(iStrTb.String(HTTP::EDate,RHTTPSession::GetTable()), dateVal);
       
   108 </codeblock></section>
       
   109 <section id="GUID-D1120183-9158-44D6-B64B-A9D8263B7174"><title>Host</title><p>This is a client request header. <b>Note:</b> The
       
   110 client should not set this header for any request unless the URL is relative. </p><codeblock id="GUID-A20C80EF-185A-57EF-9F36-D547D5E458C0" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
   111 // Set a host 'www.symbian.com', i.e. Host: www.symbian.com 
       
   112 _LIT8(host, "www.symbian.com");
       
   113 RStringF hostValStr = iStrTb.OpenFStringL(host);
       
   114 CleanupClosePushL(hostValStr);   
       
   115 THTTPHdrVal hostVal(hostValStr);    
       
   116 hdr.SetFieldL(hostStr, hostVal);
       
   117 CleanupStack::PopAndDestroy(&amp;hostValStr);</codeblock></section>
       
   118 <section id="GUID-8AA02D22-54A6-4250-9350-D9DE3B0E93B5"><title>Transfer-Encoding</title><p>This is a general header, that
       
   119 is, it applies to the connection between client and server. <b>Note:</b> The
       
   120 client should not set this header for any request, as it will be ignored. </p><codeblock id="GUID-868090A3-4534-54DE-8B46-B19BA4077B10" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
   121 // Set the transfer encoding to be 'chunked', i.e. Transfer-Encoding: chunked 
       
   122 THTTPHdrVal xferEncVal;
       
   123 xferEncVal.SetStrF(iStrTb.StringF(HTTP::EChunked,RHTTPSession::GetTable()));
       
   124 hdr.SetFieldL(iStrTb.StringF(HTTP::ETransferEncoding,RHTTPSession::GetTable()), xferEncVal);
       
   125 </codeblock></section>
       
   126 <section id="GUID-E3C924A2-E426-496E-BFDD-BA6E85E40F09"><title>User-Agent</title><p>This is a client request header. </p> <codeblock id="GUID-987775EF-4346-57C3-84DB-4C05683DD5D8" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
   127 // Set up a user agent with two part, i.e. User-Agent: CERN-LineMode/2.15 libwww/2.17b3 
       
   128 RStringF ua1Str = iStrP.OpenFStringL(_L8("CERN-LineMode/2.15"));
       
   129 CleanupClosePushL(ua1Str);
       
   130 RStringF ua2Str = iStrP.OpenFStringL(_L8("libwww/2.17b3"));
       
   131 CleanupClosePushL(ua2Str);
       
   132 RStringF uaStr = iStrP.StringF(HTTP::EUserAgent,RHTTPSession::GetTable());
       
   133 THTTPHdrVal uaVal(ua1Str);
       
   134 hdr.SetFieldL(uaStr, uaVal);
       
   135 // sets part 1 uaVal.SetStrF(ua2Str);
       
   136 hdr.SetFieldL(uaStr, uaVal);
       
   137 // sets part 2
       
   138 CleanupStack::PopAndDestroy(2);</codeblock></section>
       
   139 <section id="GUID-8127BB03-00A9-4815-83F8-69838862B17A"><title>WWW-Authenticate</title><p>This is a server response header. <b>Note:</b> The
       
   140 client need not read this header for most normal responses. </p> <codeblock id="GUID-5ED4C598-80E5-5514-A616-AFCA5D1D4002" xml:space="preserve">RHTTPHeaders hdr = aReq.GetHeaderCollection();
       
   141 ...
       
   142 // Display realm for WWW-Authenticate header 
       
   143 RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable());
       
   144             if (fieldNameStr == wwwAuth)
       
   145                 {
       
   146                 // check the auth scheme is 'basic'
       
   147                 RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable());
       
   148                 RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable());
       
   149                 THTTPHdrVal realmVal;
       
   150                 if ((fieldVal.StrF() == basic) &amp;&amp; 
       
   151                     (!hdr.GetParam(wwwAuth, realm, realmVal)))
       
   152                     {
       
   153                     RStringF realmValStr = strP.StringF(realmVal.StrF());
       
   154                     fieldVal16.Copy(realmValStr.DesC());
       
   155                     iUtils.Test().Printf(_L("Realm is: %S\n"), &amp;fieldVal16);
       
   156                     realmValStr.Close();
       
   157                     }
       
   158                 basic.Close();
       
   159                 realm.Close();
       
   160                 }
       
   161             wwwAuth.Close();
       
   162 hdr.Close();</codeblock></section>
       
   163 </conbody></concept>