All About Symbian - Nokia (S60) and Sony Ericsson (UIQ) smartphones unwrapped

  #1  
Old 30-08-2011, 12:44 PM
ramtrg ramtrg is offline
Registered User
 
Join Date: Aug 2011
Posts: 1
ramtrg is on a distinguished road
Thumbs up HTTP Post problem in Symbian C++

I have tried HTTP Post in Symbian Application.In that he values are not sending to PHP file. My Test1AppUi.cpp and Test1AppUi.h files are below...Is this coding is correct? please help me...


Test1AppUi.cpp:

Code:
void CTest1AppUi::PostRequestL(const TDesC& aUsername,const TDesC& aPassword)
{

//CEikonEnv::Static()->InfoMsg(aUsername);
//CEikonEnv::Static()->InfoMsg(aPassword);

_LIT8(KPostParamName1, "number");
_LIT8(KPostParamName2, "msg");  


TBuf8<50>   iTemp;
TBuf8<50>   iTemp2;

iTemp.Copy(aUsername);  
iTemp2.Copy(KPostParamName1);
iFormEncoder->AddFieldL(iTemp2,iTemp);

iTemp.Copy(aPassword);  
iTemp2.Copy(KPostParamName2);
iFormEncoder->AddFieldL(iTemp2,iTemp);



_LIT8(KUserAgent, "LiveTrack"); // Name of this client app
_LIT8(KAccept, "text/*");// Accept any (but only) text content


    TBufC<12> myNo(_L("success1"));
    TPtr my(myNo.Des());
    CEikonEnv::Static()->InfoMsg(my);

_LIT8(KUri,"http://www.mysite.com/fasttrack/HttpTest.php");
TUriParser8 parser;// Uri parser object
parser.Parse(KUri);//Parse the URI descriptor 


iTransaction = iSession.OpenTransactionL(parser, *this, iSession.StringPool().StringF(HTTP::EPOST, RHTTPSession::GetTable())); 
RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
SetHeaderL(hdr, HTTP::EAccept, KAccept);


iTransaction.Request().SetBody(*iFormEncoder);
iTransaction.SubmitL();

/*CEikonEnv::Static()->InfoMsg(aPassword);
    TBufC<12> myNo(_L("success1"));
    TPtr my(myNo.Des());
    CEikonEnv::Static()->InfoMsg(my);*/

}


TBool CTest1AppUi::GetNextDataPart(TPtrC8& aDataPart)
    {
    retVal = EFalse;
    GetValues(aDataPart);
    return retVal;
   }


TBool CTest1AppUi::GetValues(TPtrC8& aDataPart)
    {
    TInt err = iPostData.Read(iDataPart);
         if (KErrNone == err)
          {
             aDataPart.Set(iDataPart);
             retVal = (iDataPart.Length() == 0);
          }
         return retVal;
    }



void CTest1AppUi::ReleaseData()
    {
    GetValues(bodyData);
    }

TInt CTest1AppUi::OverallDataSize()
    {
    TInt dataSize = 0;
    // Ignore error return from Size()
     iPostData.Size(dataSize);
    return (dataSize == 0 ? KErrNotFound : dataSize);
    }

TInt CTest1AppUi::Reset()
{
    TInt pos = 0;
    return iPostData.Seek(ESeekStart, pos);
}



void CTest1AppUi::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) 
{
    switch (aEvent.iStatus) 
    { 
    case THTTPEvent::EGotResponseHeaders: 
        { 
        RHTTPResponse resp = aTransaction.Response();
        TInt status = resp.StatusCode();



        } 
        break; 


    case THTTPEvent::EGotResponseBodyData: 
        { 
        MHTTPDataSupplier* body = aTransaction.Response().Body();
        //TPtrC8 bodyData;
        TBool noMoreData = body->GetNextDataPart(bodyData);
        body->ReleaseData();
    } 
        break; 

    case THTTPEvent::EResponseComplete: 
        { 
        // The transactionís response is complete


        } 
        break; 
    case THTTPEvent::ESucceeded: 
        { 
        // Transaction completed successfully,
        // we can close it now
        aTransaction.Close();


        } 
        break; 
    case THTTPEvent::EFailed: 
        { 
        // Transaction failed for some reason
        aTransaction.Close();
        } 
        break; 

    default:
        // Check if there was any framework
        // specific error
        if (aEvent.iStatus < 0)
        {
            aTransaction.Close();


        }
        break;
    } 
}

TInt CTest1AppUi::MHFRunError(TInt /*aError*/, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
{
// Cleanup any resources in case MHFRunL() leaves
return KErrNone;
}

void CTest1AppUi::SetHeaderL(RHTTPHeaders aHeaders,TInt aHdrField,const TDesC8& aHdrValue)
{
RStringF valStr =iSession.StringPool().OpenFStringL(aHdrValue);
CleanupClosePushL(valStr);
THTTPHdrVal val(valStr);
aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val);
CleanupStack::PopAndDestroy(); // valStr
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////



void CTest1AppUi::ConstructL()
    {
    // [[[ begin generated region: do not modify [Generated Contents]

    BaseConstructL( EAknEnableSkin  | 
                     EAknEnableMSK ); 
    InitializeContainersL();
    iSession.OpenL();


    delete iFormEncoder;
    iFormEncoder = NULL;
    iFormEncoder = CHTTPFormEncoder::NewL();

    TBufC<12> myNonModifiableBuf(_L("ramprasad"));

     TPtr myModifiablePtr(myNonModifiableBuf.Des());

    TBufC<12> myModifiableBuf(_L("1234567890"));

     TPtr myModifiPtr(myModifiableBuf.Des());

    // CEikonEnv::Static()->InfoMsg(myModifiablePtr);

    // CEikonEnv::Static()->InfoMsg(myModifiableBuf);
     PostRequestL(myModifiablePtr,myModifiPtr);

    }

Test1AppUi.h:


Code:
#ifndef TEST1APPUI_H
#define TEST1APPUI_H
#include<CHTTPFormEncoder.h>
#include <http\MHTTPAuthenticationCallback.h>
#include<http\MHTTPTransactionCallback.h>
#include <e32test.h>
#include <f32file.h>
#include<http\MHTTPDataSupplier.h>
// [[[ begin generated region: do not modify [Generated Includes]
#include <aknviewappui.h>
// ]]] end generated region [Generated Includes]

// [[[ begin generated region: do not modify [Generated Forward Declarations]
class CTest1ContainerView;
// ]]] end generated region [Generated Forward Declarations]

/**
 * @class   CTest1AppUi Test1AppUi.h
 * @brief The AppUi class handles application-wide aspects of the user interface, including
 *        view management and the default menu, control pane, and status pane.
 */
class CTest1AppUi : public CAknViewAppUi,public MHTTPDataSupplier,public MHTTPTransactionCallback
    {
public: 
    // constructor and destructor
    CTest1AppUi();
    virtual ~CTest1AppUi();
    void ConstructL();


    CHTTPFormEncoder* iFormEncoder;
    void PostRequestL(const TDesC& aUsername,const TDesC& aPassword);
    // methods inherited from MHTTPDataSupplier
            virtual TBool GetNextDataPart(TPtrC8& aDataPart);
            virtual void ReleaseData();
            virtual TInt OverallDataSize();
            virtual TInt Reset();
            RFile iPostData;
            TDes8 iDataPart;
            TBool retVal;
            TBool GetValues(TPtrC8& aDataPart);
            TPtrC8 bodyData;

    //From MHTTPTransactionCallback
            virtual void MHFRunL(RHTTPTransaction aTransaction,const THTTPEvent& aEvent);
            virtual TInt MHFRunError(TInt aError,RHTTPTransaction aTransaction,const THTTPEvent& aEvent);

            RHTTPSession iSession;
            RHTTPTransaction iTransaction;
    void SetHeaderL(RHTTPHeaders aHeaders,TInt aHdrField,const TDesC8& aHdrValue);
    IMPORT_C RHTTPTransaction OpenTransactionL(const TUriC8 &aURI, MHTTPTransactionCallback &aCallback, RStringF aMethod=RStringF());



public:
    // from CCoeAppUi
    TKeyResponse HandleKeyEventL(
                const TKeyEvent& aKeyEvent,
                TEventCode aType );

    // from CEikAppUi
    void HandleCommandL( TInt aCommand );
    void HandleResourceChangeL( TInt aType );

    // from CAknAppUi
    void HandleViewDeactivation( 
            const TVwsViewId& aViewIdToBeDeactivated, 
            const TVwsViewId& aNewlyActivatedViewId );

private:
    void InitializeContainersL();
    // [[[ begin generated region: do not modify [Generated Methods]
public: 
    // ]]] end generated region [Generated Methods]

    // [[[ begin generated region: do not modify [Generated Instance Variables]
private: 
    CTest1ContainerView* iTest1ContainerView;
    // ]]] end generated region [Generated Instance Variables]


    // [[[ begin [User Handlers]
protected: 
    // ]]] end [User Handlers]

    };



#endif // TEST1APPUI_H  

:icon14:
Ads
 

Bookmarks

Tags
http, post, problem, symbia60, symbian, symbian applications

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
running application in C on mobile phone with Symbian johnyjj2 Nokia Nseries S60 5.0 phones (Nokia N97 and Nokia N97 mini) 1 22-11-2009 06:41 PM
Psion plc benefits most from Symbian phones flying off shelves in Christmas rush. trickyt Community Waffle 6 28-11-2006 08:36 PM
Symbian Announce Q3 2004 Results Ewan Symbian OS News 4 11-11-2004 02:36 PM
Symbian launches Symbian OS v7.0s at Exposium03 Rafe Symbian OS News 5 08-05-2003 09:08 PM
Handango join Symbian Platinum Partner Program Rafe Symbian OS News 0 29-04-2003 12:40 AM



All times are GMT. The time now is 08:15 AM.


vBulletin skins developed by: eXtremepixels
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright Notes || Contact Us || Privacy Policy