hi, there is a problem when i use http to post data,
the first time, after sending post request, everything goes well, but the second time,it fail with HTTP-CORE 0,
i check the document which said it is caused "RHTTPSession session is already open".
but i have no idea where goes wrong,
i use the codes from the example, Anyone who knows the answer please figure it out, thanks deeply!!!
the SetupConnectionL() function is as following:
{
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
iConnectionDone = 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 (iConnectionDone && !FindExistingConnection())
{
iConnectionDone = EFalse;
}
if (iConnectionDone)
{
// 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))) );
iConnectionDone = ETrue;
}
}




