Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    May 2006

    Custom HTTP Header Name in POST Request

    I'm using Symbian OS v7.0s on a Samsung SGH-D720. I have a requirement to use custom HTTP Header names in my POST request. The pre-canned ones in the HTTP String Pool Table defined in RHTTPSession are not good enough.

    I managed to find a way to Set a custom header "Name" by defining my own String Table. I called it CustomHeaderStringTable. Here is the .st file:
    # Customer Header String Table
    fstringtable CustomHeaderStringTable
    !// Some custom header strings
    # This comment won't appear in the .h file, but the one above will.
    EXProtocol X-Protocol

    I compiled the above using perl as given on this URL:

    And it generated:
    class CustomHeaderStringTable
    enum TStrings
    // Some custom header strings
    /** X-Protocol */
    static const TStringTable Table;

    #endif // STRINGTABLE_CustomHeaderStringTable

    Then I tried using this in my AddCustomHeaderL() method like this:

    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    // Add headers appropriate to all methods
    AddHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    AddHeaderL(hdr, HTTP::EContentType, KContentTypeValue);
    AddHeaderL(hdr, HTTP::EConnection, KConnectionValue);
    AddCustomHeaderL(hdr, CustomHeaderStringTable::EXProtocol, KXProtocolValue);
    // print the value of hdr
    THTTPHdrVal val2;
    hdr.GetField(pool.StringF(CustomHeaderStringTable::EXProtocol,CustomHeaderStringTable::Table), 0, val2);
    TBuf<100> buf2; buf2.Copy(val2.Str().DesC()); iLog.Write(buf2);
    // submit

    void CHttpClient::AddCustomHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
    RStringPool pool;

    RStringF valStr = pool.OpenFStringL(aHdrValue);

    THTTPHdrVal val(valStr);
    aHeaders.SetFieldL(pool.StringF(aHdrField,CustomHeaderStringTable::Table), val);


    The problem is even after calling AddCustomHeaderL(), the header name appears as one of the pre-canned ones. To be precise, it shows up as "CONNECT" (HTTP::ECONNECT) which is the enumerated ID 1 in the HTTP String Pool. I want the header name to be "X-Protocol".

    The RHTTPHeaders class seems to have a bug because before I submit the Http transaction, I print all the Headers in it and it HAS my "X-Protocol" header. But when it does the actual submit, it goes out as "CONNECT". This is totally weird.

    Does anybody have experience dealing with this situation?
    Any help on this will be appreciated.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Ahmedabad, India

    Re: Custom HTTP Header Name in POST Request


    I tried adding a new string in the string pool using the link provided by you.
    But Now I am getting a linking error saying

    "STRINGTABLE.obj : error LNK2005: "public: static struct TStringTable const TCus
    tomHeaderStringTable::Table" (?Table@TCustomHeaderStringTable@@2UTStringTable@@B
    ) already defined in EXAMPLECLIENTENGINE.obj"

    Can you please help me in solving it.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Ahmedabad, India

    Re: Custom HTTP Header Name in POST Request


    I am able to send the customised header.
    The problem with your code is:

    void CClientEngine::AddCustomHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
    const TDesC8& aHdrValue)
    RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
    THTTPHdrVal val(valStr); aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,
    CustomHeaderStringTable::Table), val);

    Dont use a new variable of StringPool type.

Similar Threads

  1. Replies: 6
    Last Post: 2008-05-15, 07:55
  2. Problems with HTTP POST
    By Summerman in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-11-27, 09:25
  3. HTTP Client - Synchronous HTTP POST Calls?
    By symbian_ravi in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2006-04-16, 11:51
  4. Error while sending HTTP Post Request
    By bhonsle in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2004-01-11, 16:28
  5. 7650 J2ME/MIDP HTTP Post
    By cwalkinshaw in forum Mobile Java General
    Replies: 2
    Last Post: 2002-10-23, 10:12

Posting Permissions

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