×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Problem with POST request to server

    Hi everybody,
    I`ve been running the HTTPClientExample to make a POST request against my server and it works fine, retuning "POST /position/getposition HTTP/1.1" 200 305 "-" "SimpleClient 1.0".
    The problem is that when I add this code to my app, when I try to make a POST request the server returns
    "POST /position/getPosition HTTP/1.1" 200 307 "-" "Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 blablabla..."
    and the page is not shown. I think I added HTTP request code correctly, and in the example app works fine but not adding that code to my application
    Could be he problem in CClientEngine::MHFRunL? any other idea?
    thanks

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: Problem with POST request to server

    You can debug the problem by placing breakpoints in MFhRunL() and MHFRunError().

    IF proble didnt resolved post your http engine code here and how your are making object, instantiating connection etc information.
    Regards,
    Shafali

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    I'm using Browser Control API as web browser.
    I just want to send 2 parameters by HTTP POST request. Is is the simplest way?
    When I run it in emulator crashes with Panic -11 just when I load the fist app's page. And on real device it crashes when I try to make the HTTP POST request.Please, any idea????
    Ok, here is the code:

    //BrCtlSanpleAppContainer.cpp:
    ...
    _LIT(url, "http://my_server/getposition");//Serever
    TBuf8<256> url8;
    url8.Copy(url);
    _LIT8(KMimeType, "text/plain");

    TBuf8<256> postData8;
    _LIT8(postData, "lat=11&long=22");
    postData8.Copy(postData);

    CClientEngine* iClient;
    iClient = CClientEngine::NewL(*this);
    iClient->CancelTransaction();
    iClient->IssueHTTPPostL(url8, KMimeType,postData8);
    ...

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    //And here is ClientEngine.cpp:
    #include <avkon.hrh>
    #include <aknnotewrappers.h>
    #include <aknlists.h> // CAknSinglePopupMenuStyleListBox
    #include <uri8.h>
    #include <http.h>
    #include <stringloader.h>
    #include <chttpformencoder.h>
    #include <HttpStringConstants.h>
    #include <http\RHTTPTransaction.h>
    #include <http\RHTTPSession.h>
    #include <http\RHTTPHeaders.h>
    #include <COMMDB.H> //Communications database
    #include <CDBPREFTABLE.H> //Connection Preferences table
    #include <CommDbConnPref.h>
    #include <es_enum.h> // TConnectionInfoBuf

    #include "Client.pan"
    #include "Client.hrh"
    #include "ClientEngine.h"

    #include "BrCtlSampleApp.RSG"

    // Used user agent for requests
    _LIT8(KUserAgent, "SimpleClient 1.0");


    // This client accepts all content types.
    // (change to e.g. "text/plain" for plain text only)
    _LIT8(KAccept, "*/*");

    const TInt KStatustextBufferSize = 32;
    const TInt KInfotextBufferSize = 64;
    const TInt KURIBufferSize = 128;




    // ----------------------------------------------------------------------------
    // CClientEngine::NewL()
    //
    // Creates instance of CClientEngine.
    // ----------------------------------------------------------------------------
    CClientEngine* CClientEngine::NewL(MClientObserver& aObserver)
    {
    CClientEngine* self = CClientEngine::NewLC(aObserver);
    CleanupStack::Pop(self);
    return self;
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::NewLC()
    //
    // Creates instance of CClientEngine.
    // ----------------------------------------------------------------------------
    CClientEngine* CClientEngine::NewLC(MClientObserver& aObserver)
    {
    CClientEngine* self = new (ELeave) CClientEngine(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::CClientEngine()
    //
    // First phase constructor.
    // ----------------------------------------------------------------------------
    CClientEngine::CClientEngine(MClientObserver& aObserver)
    : iObserver(aObserver),
    iPostData(NULL),
    iRunning(EFalse),
    iConnectionSetupDone(EFalse),
    iPrevProfileId(-1)
    {
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::~CClientEngine()
    //
    // Destructor.
    // ----------------------------------------------------------------------------
    CClientEngine::~CClientEngine()
    {
    delete iRepository;

    iSession.Close();

    // and finally close handles
    iConnection.Close();
    iSocketServ.Close();

    delete iPostData;
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::ConstructL()
    //
    // Second phase construction.
    // ----------------------------------------------------------------------------
    void CClientEngine::ConstructL()
    {
    iRepository = CRepository::NewL( KCRUidProfileEngine );
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::SetupConnectionL()
    //
    //
    // ----------------------------------------------------------------------------
    void CClientEngine::SetupConnectionL()
    {
    TInt bearerFilter = EApBearerTypeAllBearers;
    TInt currentProfileId;

    // Check whether we are offline or online
    iRepository->Get(KProEngActiveProfile, currentProfileId);

    // Close the connection only if
    // a) this is not the first time and
    // b) the profile has changed and
    // c) either the previous or the current profile is Offline (5 = Offline)
    if (iPrevProfileId != -1 && iPrevProfileId != currentProfileId &&
    (iPrevProfileId == 5 || currentProfileId == 5))
    {
    // Close and uninitialize
    iConnectionSetupDone = EFalse;
    iSession.Close();
    iConnection.Close();
    iSocketServ.Close();
    }

    // Save current profile id
    iPrevProfileId = currentProfileId;

    // Try to find an existing connection. If connection has not been set up,
    // iConnection is not initialized and FindExistingConnection() fails.
    // Thus, in that case, finding must not be carried out.
    if (iConnectionSetupDone && !FindExistingConnection())
    {
    iConnectionSetupDone = EFalse;
    }

    if (iConnectionSetupDone)
    {
    // Connection setup is done
    return;
    }

    // Open RHTTPSession with default protocol ("HTTP/TCP")
    iSession.OpenL();

    // Install this class as the callback for authentication requests. When
    // page requires authentication the framework calls GetCredentialsL to get
    // user name and password.
    InstallAuthenticationL(iSession);

    // In offline, only WLAN connections are available
    if (currentProfileId == 5)
    {
    bearerFilter = EApBearerTypeWLAN;
    }

    // Show IAP selection dialog
    CActiveApDb* aDb = CActiveApDb::NewL();
    CleanupStack::PushL(aDb);

    CApSettingsHandler* settings = CApSettingsHandler::NewLC(
    *aDb,
    ETrue,
    EApSettingsSelListIsPopUp,
    EApSettingsSelMenuSelectNormal,
    KEApIspTypeAll,
    bearerFilter,
    KEApSortNameAscending,
    0,
    EVpnFilterBoth,
    ETrue);

    TInt iapRet = settings->RunSettingsL(0, iSelectedIap);
    CleanupStack::PopAndDestroy(settings);
    CleanupStack::PopAndDestroy(aDb);
    if (iapRet != KApUiEventSelected)
    {
    // Exit no selection
    User::Leave(KErrNotReady);
    }
    else
    {
    // IAP Selected
    // Open socket server and start the connection
    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));
    // Now we have the iap Id. Use it to connect for the connection
    TCommDbConnPref connectPref;
    // Setup preferences
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    // Sets the CommDb ID of the IAP to use for this connection
    connectPref.SetIapId(iSelectedIap);
    // Start connection
    User::LeaveIfError(iConnection.Start(connectPref));
    // Set the sessions connection info...
    RStringPool strPool = iSession.StringPool();
    RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
    // ...to use our socket server and connection
    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );
    // ...to use our connection
    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ),
    THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) );

    iConnectionSetupDone = ETrue;
    }
    }

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    // ----------------------------------------------------------------------------
    // Enumerates through existing connections and tries to find one that matches
    // the selected IAP. If one is found, ETrue is returned; otherwise, EFalse.
    // ----------------------------------------------------------------------------
    TBool CClientEngine::FindExistingConnection()
    {
    TBool connected = EFalse;
    TConnectionInfoBuf connInfo;
    TUint count;
    if (iConnection.EnumerateConnections(count) == KErrNone)
    {
    for (TUint i=1; i<=count; i++)
    {
    // Note: GetConnectionInfo expects 1-based index.
    if (iConnection.GetConnectionInfo(i, connInfo) == KErrNone)
    {
    if (connInfo().iIapId == iSelectedIap)
    {
    connected = ETrue;
    break;
    }
    }
    }
    }
    return connected;
    }





    // ----------------------------------------------------------------------------
    // CClientEngine::IssueHTTPPostL()
    //
    // Start a new HTTP POST transaction.
    // ----------------------------------------------------------------------------
    void CClientEngine::IssueHTTPPostL(const TDesC8& aUri,
    const TDesC8& aContentType,
    const TDesC8& aBody)
    {
    // Parse string to URI
    TUriParser8 uri;
    uri.Parse(aUri);

    // Copy data to be posted into member variable; iPostData is used later in
    // methods inherited from MHTTPDataSupplier.
    delete iPostData;
    iPostData = 0;
    iPostData = aBody.AllocL();

    // Create HTTP connection
    TRAPD(err, SetupConnectionL());
    // User didn't select an IAP
    if (err == KErrNotReady) {

    HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED);
    iObserver.ClientEvent(*resTxCancelled);
    CleanupStack::PopAndDestroy(resTxCancelled);

    return;
    }

    // Get request method string for HTTP POST
    RStringF method = iSession.StringPool().StringF(HTTP::EPOST,
    RHTTPSession::GetTable());


    // Open transaction with previous method and parsed uri. This class will
    // receive transaction events in MHFRunL and MHFRunError.
    iTransaction = iSession.OpenTransactionL(uri, *this, method);

    // Set headers for request; user agent, accepted content type and body's
    // content type.
    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    SetHeaderL(hdr, HTTP::EAccept, KAccept);
    SetHeaderL(hdr, HTTP::EContentType, aContentType);

    // Set this class as an data supplier. Inherited MHTTPDataSupplier methods
    // are called when framework needs to send body data.
    MHTTPDataSupplier* dataSupplier = this;
    iTransaction.Request().SetBody(*dataSupplier);

    // Submit the transaction. After this the framework will give transaction
    // events via MHFRunL and MHFRunError.
    iTransaction.SubmitL();

    iRunning = ETrue;

    HBufC* resConnecting = StringLoader::LoadLC(R_HTTP_CONNECTING);
    iObserver.ClientEvent(*resConnecting);
    CleanupStack::PopAndDestroy(resConnecting);

    }

    // ----------------------------------------------------------------------------
    // CClientEngine::CancelTransaction()
    //
    // Cancels currently running transaction and frees resources related to it.
    // ----------------------------------------------------------------------------
    void CClientEngine::CancelTransaction()
    {
    if(!iRunning)
    return;

    // Close() also cancels transaction (Cancel() can also be used but
    // resources allocated by transaction must be still freed with Close())
    iTransaction.Close();

    // Not running anymore
    iRunning = EFalse;

    HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED);
    iObserver.ClientEvent(*resTxCancelled);
    CleanupStack::PopAndDestroy(resTxCancelled);

    }


    // ----------------------------------------------------------------------------
    // CClientEngine::MHFRunL()
    //
    // Inherited from MHTTPTransactionCallback
    // Called by framework to pass transaction events.
    // ----------------------------------------------------------------------------
    void CClientEngine::MHFRunL(RHTTPTransaction aTransaction,
    const THTTPEvent& aEvent)
    {

    switch (aEvent.iStatus)
    {
    case THTTPEvent::EGotResponseHeaders:
    {
    // HTTP response headers have been received. Use
    // aTransaction.Response() to get the response. However, it's not
    // necessary to do anything with the response when this event occurs.

    // Get HTTP status code from header (e.g. 200)
    RHTTPResponse resp = aTransaction.Response();
    TInt status = resp.StatusCode();

    // Get status text (e.g. "OK")
    TBuf<KStatustextBufferSize> statusText;
    statusText.Copy(resp.StatusText().DesC());

    HBufC* resHeaderReceived = StringLoader::LoadLC(R_HTTP_HEADER_RECEIVED, statusText, status);
    iObserver.ClientEvent(*resHeaderReceived);
    CleanupStack::PopAndDestroy(resHeaderReceived);

    }
    break;

    case THTTPEvent::EGotResponseBodyData:
    {
    // Part (or all) of response's body data received. Use
    // aTransaction.Response().Body()->GetNextDataPart() to get the actual
    // body data.

    // Get the body data supplier
    MHTTPDataSupplier* body = aTransaction.Response().Body();
    TPtrC8 dataChunk;

    // GetNextDataPart() returns ETrue, if the received part is the last
    // one.
    TBool isLast = body->GetNextDataPart(dataChunk);
    iObserver.ClientBodyReceived(dataChunk);

    HBufC* resBytesReceived = StringLoader::LoadLC(R_HTTP_BYTES_RECEIVED, dataChunk.Length());
    iObserver.ClientEvent(*resBytesReceived);
    CleanupStack::PopAndDestroy(resBytesReceived);

    // NOTE: isLast may not be ETrue even if last data part received.
    // (e.g. multipart response without content length field)
    // Use EResponseComplete to reliably determine when body is completely
    // received.
    if (isLast)
    {

    HBufC* resBodyReceived = StringLoader::LoadLC(R_HTTP_BODY_RECEIVED);
    iObserver.ClientEvent(*resBodyReceived);
    CleanupStack::PopAndDestroy(resBodyReceived);

    }

    // Always remember to release the body data.
    body->ReleaseData();
    }
    break;

    case THTTPEvent::EResponseComplete:
    {
    // Indicates that header & body of response is completely received.
    // No further action here needed.

    HBufC* resTxComplete = StringLoader::LoadLC(R_HTTP_TX_COMPLETE);
    iObserver.ClientEvent(*resTxComplete);
    CleanupStack::PopAndDestroy(resTxComplete);

    }
    break;

    case THTTPEvent::ESucceeded:
    {
    // Indicates that transaction succeeded.

    HBufC* resTxSuccessful = StringLoader::LoadLC(R_HTTP_TX_SUCCESSFUL);
    iObserver.ClientEvent(*resTxSuccessful);
    CleanupStack::PopAndDestroy(resTxSuccessful);

    // Transaction can be closed now. It's not needed anymore.
    aTransaction.Close();
    iRunning = EFalse;
    }
    break;

    case THTTPEvent::EFailed:
    {
    // Transaction completed with failure.

    HBufC* resTxFailed = StringLoader::LoadLC(R_HTTP_TX_FAILED);
    iObserver.ClientEvent(*resTxFailed);
    CleanupStack::PopAndDestroy(resTxFailed);

    aTransaction.Close();
    iRunning = EFalse;
    }
    break;

    default:
    // There are more events in THTTPEvent, but they are not usually
    // needed. However, event status smaller than zero should be handled
    // correctly since it's error.
    {
    if (aEvent.iStatus < 0)
    {

    HBufC* resNoInternetConnection = StringLoader::LoadLC(
    R_HTTP_NO_INTERNET_CONNECTION, aEvent.iStatus);
    iObserver.ClientEvent(*resNoInternetConnection);
    CleanupStack::PopAndDestroy(resNoInternetConnection);

    // Close the transaction on errors
    aTransaction.Close();
    iRunning = EFalse;
    }
    else
    {
    // Other events are not errors (e.g. permanent and temporary
    // redirections)


    HBufC* resUnrecognisedEvent = StringLoader::LoadLC(R_HTTP_UNRECOGNISED_EVENT, aEvent.iStatus);
    iObserver.ClientEvent(*resUnrecognisedEvent);
    CleanupStack::PopAndDestroy(resUnrecognisedEvent);

    }
    }
    break;
    }

    }
    ...


    // ----------------------------------------------------------------------------
    // CClientEngine::MHFRunError()
    //
    // Inherited from MHTTPTransactionCallback
    // Called by framework when *leave* occurs in handling of transaction event.
    // These errors must be handled, or otherwise HTTP-CORE 6 panic is thrown.
    // ----------------------------------------------------------------------------
    TInt CClientEngine::MHFRunError(TInt aError,
    RHTTPTransaction /*aTransaction*/,
    const THTTPEvent& /*aEvent*/)
    {

    // Just notify about the error and return KErrNone.
    HBufC* resMHFRunError = StringLoader::LoadLC(R_HTTP_MHFRUN_ERROR, aError);
    iObserver.ClientEvent(*resMHFRunError);
    CleanupStack::PopAndDestroy(resMHFRunError);

    return KErrNone;

    }

    // end of file

  6. #6
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: Problem with POST request to server

    Quote Originally Posted by stevepatrick View Post
    I'm using Browser Control API as web browser.
    I just want to send 2 parameters by HTTP POST request. Is is the simplest way?
    When I run it in emulator crashes with Panic -11 just when I load the fist app's page. And on real device it crashes when I try to make the HTTP POST request.Please, any idea????
    Ok, here is the code:

    //BrCtlSanpleAppContainer.cpp:
    ...
    _LIT(url, "http://my_server/getposition");//Serever
    TBuf8<256> url8;
    url8.Copy(url);
    _LIT8(KMimeType, "text/plain");

    TBuf8<256> postData8;
    _LIT8(postData, "lat=11&long=22");
    postData8.Copy(postData);

    CClientEngine* iClient;
    iClient = CClientEngine::NewL(*this);
    iClient->CancelTransaction();
    iClient->IssueHTTPPostL(url8, KMimeType,postData8);
    ...

    Where did you craete this object?

    CClientEngine* iClient;

    If you have craeted this in local function in .cpp itself. please move this declaration to header file.
    Regards,
    Shafali

  7. #7
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    Re: Problem with POST request to server

    Hi,

    Check HTTP example in forum nokia: http://www.forum.nokia.com/info/sw.n...I_Example.html

    Thanks,
    Eswar

  8. #8
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    I changed the object to the header file but still the same problem. It's strange because sometims it works until it asks for the acces point, then it crashes. Most of the time it crashes on the begining.
    I suspect the problem could be related to the UI. I call IssueHTTPPostL on my container class:

    //CBrCtlSampleAppContainer.h
    class CBrCtlSampleAppContainer : public CCoeControl, MCoeControlObserver, MBrCtlDataLoadSupplier,MClientObserver

    but did not implement the virtual functions:

    //CBrCtlSampleAppContainer.cpp
    void CBrCtlSampleAppContainer::ClientEvent(const TDesC& aEventDescription)
    {

    }


    void CBrCtlSampleAppContainer::ClientBodyReceived(const TDesC8& aBodyData)
    {

    }

    Got no more clues.
    It crashes with a Panic ViewSrv 11. I think it means that there must be something blocking the process. My app works fine and HTTPClientExample works fine, but when I put them together crashes. Please, any idea???

  9. #9
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: Problem with POST request to server

    Quote Originally Posted by stevepatrick View Post
    I changed the object to the header file but still the same problem. It's strange because sometims it works until it asks for the acces point, then it crashes. Most of the time it crashes on the begining.
    I suspect the problem could be related to the UI. I call IssueHTTPPostL on my container class:

    //CBrCtlSampleAppContainer.h
    class CBrCtlSampleAppContainer : public CCoeControl, MCoeControlObserver, MBrCtlDataLoadSupplier,MClientObserver

    but did not implement the virtual functions:

    //CBrCtlSampleAppContainer.cpp
    void CBrCtlSampleAppContainer::ClientEvent(const TDesC& aEventDescription)
    {

    }


    void CBrCtlSampleAppContainer::ClientBodyReceived(const TDesC8& aBodyData)
    {

    }

    Got no more clues.
    It crashes with a Panic ViewSrv 11. I think it means that there must be something blocking the process. My app works fine and HTTPClientExample works fine, but when I put them together crashes. Please, any idea???
    There is some problem in the merging, can u just post your header of container and .cpp of container where you have used the clientEngine.
    Regards,
    Shafali

  10. #10
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    //BrCtlSampleAppContainer.h
    #ifndef BRCTLSAMPLEAPPCONTAINER_H
    #define BRCTLSAMPLEAPPCONTAINER_H

    // INCLUDES
    #include <coecntrl.h>
    #include "BrCtlInterface.h"
    #include <lbs.h>
    #include <LbsSatellite.h>
    #include "ClientEngine.h"

    // FORWARD DECLARATIONS
    class CBrCtlSampleAppSpecialLoadObserver;
    class CBrCtlSampleAppLayoutObserver;
    class CBrCtlSampleAppSoftkeysObserver;
    class CBrCtlSampleAppLoadEventObserver;
    class CBrCtlSampleAppLinkResolver;
    class CBrCtlSampleAppStateChangeObserver;
    class CBrCtlSampleAppDialogsProvider;
    class CAknDoubleStyleListBox;
    class CLbsPositionRequestor;
    // CLASS DECLARATION

    // CONSTANTS
    // Length of degree buffer
    const TInt KDegreeLength = 19;

    // Length of time buffer
    const TInt KDateTimeLength = 125;

    // maximum length a value string may have
    const TInt KValueMaxLength = 30;


    void GetDegreesString(const TReal64& aDegrees,TBuf<KDegreeLength>& aDegreesString);
    void getPosition(TBuf<KDegreeLength>& myLatitude,TBuf<KDegreeLength>& myLongitude);
    void getAccuratePosition(TBuf<KDegreeLength>& myLatitude,TBuf<KDegreeLength>& myLongitude);
    void formatCoordinates();

    /**
    * CBrCtlSampleAppContainer class.
    * This is the container control class.
    */
    class CBrCtlSampleAppContainer : public CCoeControl, MCoeControlObserver, MBrCtlDataLoadSupplier,MClientObserver
    {
    public: // Constructors and destructor

    /**
    * EPOC default constructor.
    * @param aRect Frame rectangle for container.
    */
    void ConstructL(const TRect& aRect);

    /**
    * Destructor.
    */
    ~CBrCtlSampleAppContainer();
    void ClientEvent(const TDesC& aEventDescription);

    /*
    * ClientBodyReceived()
    *
    * Called when a part of the HTTP body is received.
    *
    * Params:
    * aBodyData: Part of the body data received. (e.g. part of
    * the received HTML page)
    *
    * Returns:
    * -
    *
    */
    void ClientBodyReceived(const TDesC8& aBodyData);


    public: // New functions

    /**
    * Call the Browser Control
    * @return void
    */
    void callBrowserControl();
    /**
    * Pass a command to the Browser Control
    * @since 2.8
    * @param aCommand The command that the Browser Control should process
    * @return void
    */
    void HandleCommandL(TInt aCommand);

    /**
    * Dynamically initialises a menu pane. The Uikon framework calls this
    * function, if it is implemented in a menu’s observer, immediately before
    * the menu pane is activated.
    * @since 2.8
    * @param aResourceId Resource ID identifying the menu pane to initialise
    * @param aMenuPane The in-memory representation of the menu pane.
    * @return void
    */
    void DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane);

    /**
    * Handles key events
    * @since 2.8
    * @param aKeyEvent The key event that occurred.
    * @param aType The window server event type that is being handled
    * @return TKeyResponse Value indicates whether or not the key event was consumed by the control. The default implementation simply returns EKeyWasNotConsumed.
    */
    TKeyResponse HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);

    /**
    * Accessor method for iText
    * @since 2.8
    * @param void
    * @return TDesc& The descriptor of the text
    */
    inline const TDesC& Text() const {return iText;}

    /**
    * Setter method for iText
    * @since 2.8
    * @param aText The descriptor for the text you wish to display
    * @return void
    */
    void SetText( const TDesC& aText );

    /**
    * Setter method for iPoint
    * @since 2.8
    * @param aPoint The point at which you want to display the text
    * @return void
    */
    void SetPoint( const TPoint& aPoint );

    /**
    * Accessor method iBrCtlInterface
    * @since 2.8
    * @param void
    * @return CBrCtlInterface* A pointer to the browser control interface as a convenience to the observers
    */
    inline CBrCtlInterface* BrCtlInterface() const {return iBrCtlInterface;}

    private: // Functions from base classes

    /**
    * From CoeControl,SizeChanged.
    */
    void SizeChanged();

    /**
    * From CoeControl,CountComponentControls.
    */
    TInt CountComponentControls() const;

    /**
    * From CCoeControl,ComponentControl.
    */
    CCoeControl* ComponentControl(TInt aIndex) const;

    /**
    * From CCoeControl,Draw.
    */
    void Draw(const TRect& aRect) const;

    /**
    * Handle key events.
    */
    TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);

    /**
    * From MBrCtlDataLoadSupplier, Cancel an on-going load
    */
    void CancelLoad();

    /**
    * Create a Basic Browser Control that does not have observers with scrolling
    * and HTTP framework capabilities
    */
    void CreateBasicBrowserControlL();

    /**
    * Create Browser Control with observers with the given capabilities
    */
    void CreateBrowserControlWithObserversL(TUint aCapabilities);

    /**
    * Read the file.
    */
    HBufC8* ReadFileLC(const TDesC& aFileName);

    /**
    * Handles an event from an observed control.
    */
    void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);

    /**
    * The following methods are used to demonstrate the functionality of
    * the browser control API
    */
    void BasicBrowserControlL();
    void BrowserControlWithObserversL();
    void LoadingContentWithFileHandleL();
    void LoadingContentWithBufferL();
    void IncrementalLoadingL();
    void SpecialLoadRequestsL();
    void CustomizedDialogsL();
    void CustomizedSoftKeysL();
    void ResolvingEmbeddedLinksL();
    void CustomizedScrollBarsL();
    void HandleStateChangedL();
    void ChangeSizeExtentsL();
    void PageInfoL();
    void ContentSizeImageCountL();

    static void GetDegreesString(const TReal64& aDegrees,TBuf<KDegreeLength>& aDegreesString);
    TReal64 CBrCtlSampleAppContainer::GetDegrees(const TReal64& aDegrees) const;
    void ShowPosition();


    private: //data
    // Pointer to the browser control interface
    CBrCtlInterface* iBrCtlInterface;
    // Desired capabilities of the browser control
    TUint iBrCtlCapabilities;
    // Command Base
    TInt iCommandBase;
    // Special Load Observer
    CBrCtlSampleAppSpecialLoadObserver* iBrCtlSampleAppSpecialLoadObserver;
    // Layout Observer
    CBrCtlSampleAppLayoutObserver* iBrCtlSampleAppLayoutObserver;
    // Softkeys Observer
    CBrCtlSampleAppSoftkeysObserver* iBrCtlSampleAppSoftkeysObserver;
    // Load Event Observer
    CBrCtlSampleAppLoadEventObserver* iBrCtlSampleAppLoadEventObserver;
    // Link Resolver
    CBrCtlSampleAppLinkResolver* iBrCtlSampleAppLinkResolver;
    // State Change Observer
    CBrCtlSampleAppStateChangeObserver* iBrCtlSampleAppStateChangeObserver;
    // Dialogs Provider
    CBrCtlSampleAppDialogsProvider* iBrCtlSampleAppDialogsProvider;
    // Informs whether or not CancelLoad has been called
    TBool iCancelInitDataLoad;
    // A graphics device to which a bitmap managed by the font and bitmap server can be drawn
    CFbsScreenDevice* iFbsScrDev;
    // Abstract font interface
    CFont* iFont;
    // Text to display to the screen if desired
    TPtrC iText;
    // Point at which to display text
    TPoint iPoint;
    //Clente HTTP
    CClientEngine* iClient;

    };

    #endif

  11. #11
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    //BrCtlSampleAppContainer.cpp
    // INCLUDE FILES
    #include "BrCtlSampleAppContainer.h"
    #include "BrCtlSampleAppSpecialLoadObserver.h"
    #include "BrCtlSampleAppLayoutObserver.h"
    #include "BrCtlSampleAppSoftkeysObserver.h"
    #include "BrCtlSampleAppLoadEventObserver.h"
    #include "BrCtlSampleAppLinkResolver.h"
    #include "BrCtlSampleAppStateChangeObserver.h"
    #include "BrCtlSampleAppDialogsProvider.h"
    #include "BrCtlSampleAppQueryDialog.h"
    #include "ClientEngine.h"
    #include <eiklabel.h> // for example label control
    #include <avkon.hrh>
    #include <BrCtlSampleApp.rsg>
    #include "brctlsampleapp.hrh"
    #include <BrCtlInterface.h>
    #include <CHARCONV.H>
    #include <gdi.h>
    #include <bitdev.h>
    #include <Lbs.h>
    #include <e32cons.h> // Console
    #include <w32std.h>
    #include <aknutils.h>
    #include <hal.h>
    #include <f32file.h> // link against efsrv.lib
    #include <aknnotewrappers.h>

    //HTTP request:
    #include <uri8.h>
    #include <e32base.h>
    #include <http.h>
    #include <httpexampleclient.h>
    #include <httpexampleutils.h>

    #include <Es_sock.h> //,RConnection ,RSocketServ
    #include <Commdbconnpref.h> //TCommDbConnPref
    #include <stringpool.h> //RStringPool
    #include <http\rhttpconnectioninfo.h> //RHTTPConnectionInfo



    // Plus sign delimeter used in formatting methods
    _LIT(KDelimPlus,"\x2b"); // "+" symbol
    // Minus sign delimeter used in formatting methods
    _LIT(KDelimMinus,"\x2d"); // "-" symbol
    // Not-a-number string
    _LIT(KNan,"NaN");
    TBuf<KDegreeLength> myLatitude,myLongitude;
    TBuf<KDegreeLength> myLastLatitude,myLastLongitude;

    //HTTP POST
    _LIT8(KUserAgent, "Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaN96-1/1.11; Profile/MIDP-2.1 Configuration/CLDC-1.1 AppleWebKit/413 (KHTML, like Gecko) Safari/413");
    // This client accepts all content types.
    // (change to e.g. "text/plain" for plain text only)
    _LIT8(KAccept, "*/*");
    const TInt KStatustextBufferSize = 32;
    const TInt KInfotextBufferSize = 64;
    const TInt KURIBufferSize = 128;
    RHTTPSession iSession;


    // ================= MEMBER FUNCTIONS =======================
    void
    CBrCtlSampleAppContainer::callBrowserControl()
    {
    BasicBrowserControlL();
    }
    void CBrCtlSampleAppContainer::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
    {
    ....
    case EBrCtlSampleAppCmdAppgetGPS:
    {
    getAccuratePosition(myLatitude,myLongitude);
    _LIT(url, "http://myServer/myPosition");//Servidor Treelogic

    TBuf8<256> url8;
    url8.Copy(url);
    _LIT8(KMimeType, "text/plain");

    TBuf8<256> postData8;
    _LIT8(postData, "lat=11&long=22");//TODO hardcoded
    postData8.Copy(postData);

    iClient = CClientEngine::NewL(*this);
    iClient->CancelTransaction();
    iClient->IssueHTTPPostL(url8, KMimeType,postData8);

    break;
    }
    ...
    }
    }
    // ----------------------------------------------------
    // CBrCtlSampleAppContainer::BasicBrowserControlL()
    // ----------------------------------------------------
    //
    void
    CBrCtlSampleAppContainer::BasicBrowserControlL()
    {

    if (iBrCtlInterface == NULL)
    {
    TRect rect(TPoint(0,0), Size());
    iBrCtlInterface = CreateBrowserControlL( this,
    rect,
    TBrCtlDefs::ECapabilityDisplayScrollBar |TBrCtlDefs::ECapabilityLoadHttpFw | TBrCtlDefs::ECapabilityGraphicalHistory| TBrCtlDefs::ECommandBack,
    iCommandBase,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL);
    }
    _LIT(KUrl, "http://myServer/");
    iBrCtlInterface->LoadUrlL( KUrl );
    }

    void CBrCtlSampleAppContainer::ClientEvent(const TDesC& aEventDescription)
    {

    }


    void CBrCtlSampleAppContainer::ClientBodyReceived(const TDesC8& aBodyData)
    {

    }
    ...

  12. #12
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: Problem with POST request to server

    Quote Originally Posted by stevepatrick View Post
    //BrCtlSampleAppContainer.cpp
    // INCLUDE FILES
    #include "BrCtlSampleAppContainer.h"
    #include "BrCtlSampleAppSpecialLoadObserver.h"
    #include "BrCtlSampleAppLayoutObserver.h"
    #include "BrCtlSampleAppSoftkeysObserver.h"
    #include "BrCtlSampleAppLoadEventObserver.h"
    #include "BrCtlSampleAppLinkResolver.h"
    #include "BrCtlSampleAppStateChangeObserver.h"
    #include "BrCtlSampleAppDialogsProvider.h"
    #include "BrCtlSampleAppQueryDialog.h"
    #include "ClientEngine.h"
    #include <eiklabel.h> // for example label control
    #include <avkon.hrh>
    #include <BrCtlSampleApp.rsg>
    #include "brctlsampleapp.hrh"
    #include <BrCtlInterface.h>
    #include <CHARCONV.H>
    #include <gdi.h>
    #include <bitdev.h>
    #include <Lbs.h>
    #include <e32cons.h> // Console
    #include <w32std.h>
    #include <aknutils.h>
    #include <hal.h>
    #include <f32file.h> // link against efsrv.lib
    #include <aknnotewrappers.h>

    //HTTP request:
    #include <uri8.h>
    #include <e32base.h>
    #include <http.h>
    #include <httpexampleclient.h>
    #include <httpexampleutils.h>

    #include <Es_sock.h> //,RConnection ,RSocketServ
    #include <Commdbconnpref.h> //TCommDbConnPref
    #include <stringpool.h> //RStringPool
    #include <http\rhttpconnectioninfo.h> //RHTTPConnectionInfo



    // Plus sign delimeter used in formatting methods
    _LIT(KDelimPlus,"\x2b"); // "+" symbol
    // Minus sign delimeter used in formatting methods
    _LIT(KDelimMinus,"\x2d"); // "-" symbol
    // Not-a-number string
    _LIT(KNan,"NaN");
    TBuf<KDegreeLength> myLatitude,myLongitude;
    TBuf<KDegreeLength> myLastLatitude,myLastLongitude;

    //HTTP POST
    _LIT8(KUserAgent, "Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaN96-1/1.11; Profile/MIDP-2.1 Configuration/CLDC-1.1 AppleWebKit/413 (KHTML, like Gecko) Safari/413");
    // This client accepts all content types.
    // (change to e.g. "text/plain" for plain text only)
    _LIT8(KAccept, "*/*");
    const TInt KStatustextBufferSize = 32;
    const TInt KInfotextBufferSize = 64;
    const TInt KURIBufferSize = 128;
    RHTTPSession iSession;


    // ================= MEMBER FUNCTIONS =======================
    void
    CBrCtlSampleAppContainer::callBrowserControl()
    {
    BasicBrowserControlL();
    }
    void CBrCtlSampleAppContainer::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
    {
    ....
    case EBrCtlSampleAppCmdAppgetGPS:
    {
    getAccuratePosition(myLatitude,myLongitude);
    _LIT(url, "http://myServer/myPosition");//Servidor Treelogic

    TBuf8<256> url8;
    url8.Copy(url);
    _LIT8(KMimeType, "text/plain");

    TBuf8<256> postData8;
    _LIT8(postData, "lat=11&long=22");//TODO hardcoded
    postData8.Copy(postData);

    iClient = CClientEngine::NewL(*this);
    iClient->CancelTransaction();
    iClient->IssueHTTPPostL(url8, KMimeType,postData8);

    break;
    }
    ...
    }
    }
    // ----------------------------------------------------
    // CBrCtlSampleAppContainer::BasicBrowserControlL()
    // ----------------------------------------------------
    //
    void
    CBrCtlSampleAppContainer::BasicBrowserControlL()
    {

    if (iBrCtlInterface == NULL)
    {
    TRect rect(TPoint(0,0), Size());
    iBrCtlInterface = CreateBrowserControlL( this,
    rect,
    TBrCtlDefs::ECapabilityDisplayScrollBar |TBrCtlDefs::ECapabilityLoadHttpFw | TBrCtlDefs::ECapabilityGraphicalHistory| TBrCtlDefs::ECommandBack,
    iCommandBase,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL);
    }
    _LIT(KUrl, "http://myServer/");
    iBrCtlInterface->LoadUrlL( KUrl );
    }

    void CBrCtlSampleAppContainer::ClientEvent(const TDesC& aEventDescription)
    {

    }


    void CBrCtlSampleAppContainer::ClientBodyReceived(const TDesC8& aBodyData)
    {

    }
    ...

    I think problem lies here:

    If you issue this command again and agian then your client object would be allocated again without deleting the previous one

    if(!iClient)
    iClient = CClientEngine::NewL(*this);

    iClient->CancelTransaction();

    //As your connection is being setup when you do issue http post you are setting connection again and again which is not required
    // juste setup the connection once you can do that in constructL() of client engine as well. then call issue httppostL() try this way.


    iClient->IssueHTTPPostL(url8, KMimeType,postData8);
    Regards,
    Shafali

  13. #13
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    Hi Shafali
    I think I didn't undertand it all.
    My new code now looks like:

    if(!iClient)
    iClient = CClientEngine::NewL(*this);

    iClient->CancelTransaction();
    iClient->IssueHTTPPostL(url8, KMimeType,postData8);

    Any other change needed in ConstructL?why?is it needed to reset iClient?
    I'm not sure if it's workink because emulator went crazy and doesn´t launch...I´ll try on a real device
    Thanks

  14. #14
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: Problem with POST request to server

    Quote Originally Posted by stevepatrick View Post
    Hi Shafali
    I think I didn't undertand it all.
    My new code now looks like:

    if(!iClient)
    iClient = CClientEngine::NewL(*this);

    iClient->CancelTransaction();
    iClient->IssueHTTPPostL(url8, KMimeType,postData8);

    Any other change needed in ConstructL?why?is it needed to reset iClient?
    I'm not sure if it's workink because emulator went crazy and doesn´t launch...I´ll try on a real device
    Thanks

    In your http class there would be setupconnection() function which would establish GPRS connection.

    You have called this function in IssueHttpPostL() which will establish connection everytime you send a request.

    So i just mean here to call setup connection only once.
    Regards,
    Shafali

  15. #15
    Registered User
    Join Date
    Jun 2009
    Posts
    27

    Re: Problem with POST request to server

    I tried running the app in a real device. The firts time runs fine until asks for access point, then I select an access point and crashes. Then when I try to run the app again it crashes when trying to launch, so I think you're right and the connection stays open.

    This is SetupConnectionL. I think it closes the connection if its not the first time:

    void CClientEngine::SetupConnectionL()
    {
    TInt bearerFilter = EApBearerTypeAllBearers;
    TInt currentProfileId;

    // Check whether we are offline or online
    iRepository->Get(KProEngActiveProfile, currentProfileId);

    // Close the connection only if
    // a) this is not the first time and
    // b) the profile has changed and
    // c) either the previous or the current profile is Offline (5 = Offline)
    if (iPrevProfileId != -1 && iPrevProfileId != currentProfileId &&
    (iPrevProfileId == 5 || currentProfileId == 5))
    {
    // Close and uninitialize
    iConnectionSetupDone = EFalse;
    iSession.Close();
    iConnection.Close();
    iSocketServ.Close();
    }


    // Save current profile id
    iPrevProfileId = currentProfileId;

    // Try to find an existing connection. If connection has not been set up,
    // iConnection is not initialized and FindExistingConnection() fails.
    // Thus, in that case, finding must not be carried out.
    if (iConnectionSetupDone && !FindExistingConnection())
    {
    iConnectionSetupDone = EFalse;
    }

    if (iConnectionSetupDone)
    {
    // Connection setup is done
    return;
    }

    // Open RHTTPSession with default protocol ("HTTP/TCP")
    iSession.OpenL();

    // Install this class as the callback for authentication requests. When
    // page requires authentication the framework calls GetCredentialsL to get
    // user name and password.
    InstallAuthenticationL(iSession);

    // In offline, only WLAN connections are available
    if (currentProfileId == 5)
    {
    bearerFilter = EApBearerTypeWLAN;
    }

    // Show IAP selection dialog
    CActiveApDb* aDb = CActiveApDb::NewL();
    CleanupStack::PushL(aDb);

    CApSettingsHandler* settings = CApSettingsHandler::NewLC(
    *aDb,
    ETrue,
    EApSettingsSelListIsPopUp,
    EApSettingsSelMenuSelectNormal,
    KEApIspTypeAll,
    bearerFilter,
    KEApSortNameAscending,
    0,
    EVpnFilterBoth,
    ETrue);

    TInt iapRet = settings->RunSettingsL(0, iSelectedIap);
    CleanupStack::PopAndDestroy(settings);
    CleanupStack::PopAndDestroy(aDb);
    if (iapRet != KApUiEventSelected)
    {
    // Exit no selection
    User::Leave(KErrNotReady);
    }
    else
    {
    // IAP Selected
    // Open socket server and start the connection
    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));
    // Now we have the iap Id. Use it to connect for the connection
    TCommDbConnPref connectPref;
    // Setup preferences
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    // Sets the CommDb ID of the IAP to use for this connection
    connectPref.SetIapId(iSelectedIap);
    // Start connection
    User::LeaveIfError(iConnection.Start(connectPref));
    // Set the sessions connection info...
    RStringPool strPool = iSession.StringPool();
    RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
    // ...to use our socket server and connection
    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );
    // ...to use our connection
    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ),
    THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) );

    iConnectionSetupDone = ETrue;
    }
    }

    I don't understand why it works fine on HTTPClientExample and crashes here. You suggest to modify the source code not to invoke SetupConnectionL() every time IssueHTTPPostL() is invoked?? Invoke SetupConnectionL() in ConstructL() and delete al SetupConnectionL() invokations in IssueHTTPPostL()?

Similar Threads

  1. POST request and authorization/authentication problem
    By badzio in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2011-04-13, 14:47
  2. A problem about Http POST
    By wanghuasong1001 in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2009-08-03, 10:09
  3. Replies: 3
    Last Post: 2008-09-09, 04:53
  4. TCP server packet receiving problem
    By raj_rr7 in forum Symbian Networking & Messaging (Closed)
    Replies: 9
    Last Post: 2007-07-12, 12:24
  5. Problem with HTTP POST
    By thathoo in forum Mobile Java General
    Replies: 2
    Last Post: 2006-12-18, 18:23

Posting Permissions

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