Hi,
I need to periodically post data via HTTP POST method. I've tried to set automatically the IAP selection, but
after the first POST method call, which succesfully transfer the data, application crashes on the device. In the emulator it works fine. I wondering where's the fault, can anybody help me, please?
The automatic selection of IAP I'm doing in method AutoSetupConnectionL(), which is called in ConstructL of HTTPClient. Objects iSocketServ, iConnection, iSession and iTransaction are HTTP client class members.
Then here's the POST method:Code:void CClientEngine::AutoSetupConnectionL() { //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(); User::LeaveIfError(iSocketServ.Connect()); User::LeaveIfError(iConnection.Open(iSocketServ)); TCommDbConnPref pref; iSelectedIap = 0; pref.SetIapId(iSelectedIap); pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); pref.SetDirection(ECommDbConnectionDirectionOutgoing); pref.SetBearerSet( ECommDbBearerGPRS | ECommDbBearerCdma2000 | ECommDbBearerLAN | ECommDbBearerCSD ); iConnection.Start(pref); RStringPool strP = iSession.StringPool(); RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) ); TInt connPtr = REINTERPRET_CAST(TInt, &iConnection); connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) ); iConnectionSetupDone = ETrue; }
Thank you, Petr.Code:void CClientEngine::HttpPostL(const TDesC8& aUri, TDesC& aFileName) { // 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(); // 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. LoadFileL(aFileName); MakePostPacketL(aFileName); RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection(); SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent); SetHeaderL(hdr, HTTP::EAccept, KAccept); SetHeaderL(hdr, HTTP::EContentType, KPostContentType); // 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); #if (DEBUG_APP == 1) TPtrC logPtr(_L("Happened iTransaction.SubmitL(); iRunning = ETrue; ")); Essential::LogL(logPtr); #endif }


Do you see any bugs ?

