×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    25

    Customized HTTP header ???

    Hi all,

    In my application, I need to add extra fields (other than standard header fields) in the HTTP header while sending the request.

    How can I create customized header in HTTP 1.0?
    I need to send a particular string which has to be in the header.

    Please respond, its urgent.

    Thanks.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: Customized HTTP header ???

    Note that string pools dynamically extend themselves whenever you try to "open" a string which does not exist. So you can "open" your own header from RHTTPSession::StringPool for example.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    25

    Exclamation Re: Customized HTTP header ???

    Hi wizard_hu_,


    Thanks for help.

    But can you please explain it in detail? How do I append extra string in the header even if I open it using StringPool?

    I mean, I need to use SetFieldL method of RHTTPHeaders to set any field in header, right?

    So how can I append my own string (when there is no standard header field for it in HTTP) ?

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: Customized HTTP header ???

    Let us assume that you have checked the "HTTPExampleClient" in the SDK.
    The first occurence of setfieldl in httpexampleclient.cpp is the following:
    hdr.SetFieldL(iSess.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), contType);
    the first argument of SetFieldL is an RStringF, so the nice little "iSess.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable())" part is about getting an "existing" string from the string table.
    the second argument is a THTTPHdrVal, and if you check that class, it can be constructed 5 ways:
    - THTTPHdrVal();
    - THTTPHdrVal(TInt aIntVal);
    - THTTPHdrVal(RStringF aStrVal);
    - THTTPHdrVal(RString aStrVal);
    - THTTPHdrVal(TDateTime aDateVal);
    So if a THTTPHdrVal happens to contain a string (and the usual values for Content-Type are all strings, like "text/plain", or anything else), it has to be still constructed using a RString/F.
    Indeed, if we extend the scope of the quotation, there will suddenly appear that "Open" I have mentioned in my previous post:
    // Content type header
    TBuf8<KMaxContentTypeSize> contTypeBuf;
    contTypeBuf.Copy(iReqBodyContentType);
    RStringF contTypeStr = iSess.StringPool().OpenFStringL(contTypeBuf);
    THTTPHdrVal contType(contTypeStr);
    hdr.SetFieldL(iSess.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), contType);
    contTypeStr.Close();
    Where "TBuf8<KMaxContentTypeSize> contTypeBuf" is obviously a descriptor, and "RStringF contTypeStr = iSess.StringPool().OpenFStringL(contTypeBuf);" is an RStringF, containing it.

    So if you want to set the famous Turtle:black HTTP header, you could use
    Code:
    _LIT8(KTurtle,"Turtle");
    _LIT8(KBlack,"black");
    RStringF turtleStr = iSess.StringPool().OpenFStringL(KTurtle);
    RStringF blackStr = iSess.StringPool().OpenFStringL(KBlack);
    THTTPHdrVal blackVal(blackStr);
    hdr.SetFieldL(turtleStr,blackVal);
    blackStr.Close();
    turtleStr.Close();
    Since SetFieldL may leave, it would be safer to use CleanupClosePushL-s, but the snippet is more readable (and resembles more to the original example) in this form.

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    25

    Re: Customized HTTP header ???

    Hey,

    got it now...

    thanks a lot for this..

Similar Threads

  1. Recording in Amr Format
    By losym in forum Symbian Media (Closed)
    Replies: 12
    Last Post: 2009-03-26, 06:41
  2. [ help ] how to add cookie in http request header
    By cysnew in forum Symbian C++
    Replies: 6
    Last Post: 2008-05-15, 07:55
  3. Custom HTTP Header Name in POST Request
    By srigans1 in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-08-25, 06:56
  4. HTTP header
    By xrsu in forum General Messaging
    Replies: 1
    Last Post: 2002-12-11, 08:11
  5. HTTP header and WAP209 header equivalence/precedence/conf licts
    By mobilecohesion in forum General Messaging
    Replies: 0
    Last Post: 2002-12-03, 11:49

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •