Hi All,
I am sending a post to webserver using default connection, code works fine on
emulator, but it doesnt work on device not even return error code, it remains in waiting state.
Please help on this as it is urgent.
Here is the code :
void CPostHelper::IssueHTTPPostL(const TDesC8& aUri,
const TDesC8& aContentType, const TDesC8& aBody, TBool ShowDialog)
{
if (IsActive())
{
Cancel();
}
delete iUri;
iUri = NULL;
delete iContentType;
iContentType = NULL;
delete iBody;
iBody = NULL;
iUri = aUri.AllocL();
iContentType = aContentType.AllocL();
iBody = aBody.AllocL();
// Create HTTP connection
TRAPD(err, SetupConnectionL());
DoHTTPPostL();
iXmlHandler = CXmlHandler::NewL();
//Only Show dialog when not showing browser
ShowWaitDialog = ShowDialog;
if(ShowWaitDialog)
{
waitDialog = new ( ELeave ) CAknWaitDialog( NULL, ETrue );
// Show the wait Dialog
waitDialog->ExecuteLD( R_AKNEXNOTE_WAIT_NOTE_SOFTKEY_CANCEL );
ShowWaitDialog = EFalse;
itimer1 = ConnectionTimer::NewL();
itimer1->StartL(KConnectionTimeOut);
}
}
void CPostHelper::SetupConnectionL()
{
if (iConnectionSetupDone)
{
//User::Leave(KErrAlreadyExists);
return;
}
if (IsActive())
{
User::Leave(KErrInUse);
}
iSession.OpenL();
InstallAuthenticationL(iSession);
CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDB);
// initialize a view
CCommsDbConnectionPrefTableView* commDBView =
commDB->OpenConnectionPrefTableInRankOrderLC(
ECommDbConnectionDirectionOutgoing);
// go to the first record
User::LeaveIfError(commDBView->GotoFirstRecord());
// Declare a prefTableView Object.
CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
// read the connection preferences
commDBView->ReadConnectionPreferenceL(pref);
TUint32 iIapID = pref.iBearer.iIapId;
// pop and destroy the IAP View
CleanupStack::PopAndDestroy(commDBView);
// pop and destroy the database object
CleanupStack::PopAndDestroy(commDB);
//iFirstTime = EFalse;
////////////////////////////
TBool connected(EFalse);
TCommDbConnPref prefs;
//prefs.SetIapId(userSelection.iId);
//prefs.SetIapId(2);//Set Uncategorised
//prefs.SetIapId(iSelectedIap);
prefs.SetIapId(iIapID);
prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
prefs.SetDirection(ECommDbConnectionDirectionOutgoing);
prefs.SetBearerSet(ECommDbBearerGPRS);
User::LeaveIfError(iSocketServ.Connect());
User::LeaveIfError(iConnection.Open(iSocketServ));
iConnection.Start(prefs, iStatus);
iConnectionSetupDone = ETrue;
connected = ETrue;
SetActive();
}
void CPostHelper:oHTTPPostL()
{
// Parse string to URI
TUriParser8 uri;
uri.Parse(*iUri);
// Copy data to be posted into member variable; iPostData is used later in
// methods inherited from MHTTPDataSupplier.
delete iPostData;
iPostData = 0;
iPostData = iBody->AllocL();
// Set the session's connection info...
RStringPool strPool = iSession.StringPool();
RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
// ...to use the socket server
connInfo.SetPropertyL(strPool.StringF(HTTP::EHttpSocketServ,
RHTTPSession::GetTable()), THTTPHdrVal(iSocketServ.Handle()));
// Get request method string for HTTP POST
//RStringF method = iSession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable());
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);
iTransactionOpen = ETrue;
//->
// 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, KContentTypeForm);
// 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();
}

oHTTPPostL()


