TInt COpenMAXALTestModule::al_SetDataFormat( CStifItemParser& aItem ) { TInt status(KErrNone); TInt type; TInt contType(0); TPtrC mimetype; status = aItem.GetNextInt(type); switch(type) { case XA_DATAFORMAT_MIME: { status = aItem.GetNextString(mimetype); if(!status) { status = aItem.GetNextInt(contType); if(!status) { if(m_MimeType) { delete m_MimeType; m_MimeType = NULL; } m_MimeType = HBufC8::NewL(mimetype.Length()+1); TPtr8 desc = m_MimeType->Des(); desc.Copy(mimetype); m_Mime.formatType = XA_DATAFORMAT_MIME; m_Mime.mimeType = (XAchar*) desc.PtrZ(); m_Mime.containerType = contType; } else { status = KErrGeneral; } } else { status = KErrGeneral; } } break; case XA_DATAFORMAT_PCM: case XA_DATAFORMAT_RAWIMAGE: break; default: status = KErrGeneral; break; } return status; }
/** This function is called to initiate the tests. It may leave with one of the system-wide error codes. */ void CTextModeTestPostBodyChunks::DoRunL() { // Open the HTTP session iSession.OpenL(); CleanupClosePushL(iSession); RStringPool strP = iSession.StringPool(); // Open a POST transactions, specifying this object as the request body // data supplier TUriParser8 up; HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KHttpPostBodyChunksUrl(), iIniSettingsFile); CleanupStack::PushL(newUrl8); TPtr8 newUrlPtr8 = newUrl8->Des(); up.Parse(newUrlPtr8); iTransaction = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EPOST,RHTTPSession::GetTable())); RHTTPRequest rq = iTransaction.Request(); rq.SetBody(*this); RHTTPHeaders hdr = rq.GetHeaderCollection(); THTTPHdrVal length(OverallDataSize()); hdr.SetFieldL(strP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()), length); THTTPHdrVal contType(strP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable())); hdr.SetFieldL(strP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), contType); // Create the delayed notifier iReleaseTimer = CDelayedBodyDataNotifier::NewL(iTransaction); CleanupStack::PushL(iReleaseTimer); CActiveScheduler::Add(iReleaseTimer); // Submit the transaction iTransaction.SubmitL(); iFailureError = KErrNone; CActiveScheduler::Start(); // Get the completion code and inform the engine. Anything other than // HTTP/200 status is a failure for this test. iEngine->SetCurrentStatusCode(iTransaction.Response().StatusCode()); iExpectedStatusCode = 200; // Close anything opened CleanupStack::PopAndDestroy(3, &iSession); // and iReleaseTimer, newUrl8; // Check for failure error codes caught in MHFRunL User::LeaveIfError(iFailureError); }
TBool CTestTransaction::AddRequestBodyL( RHTTPHeaders &aHeaders, RStringPool &aStrPool) { // the content type info will be in $ContentType$. If NULL or Empty then an error generated TBuf8<KMaxContentTypeSize> contTypeBuf; contTypeBuf.Copy(Machine()->GetDefine(KITHContentType)); if (contTypeBuf.Length() == 0) return EFalse; //Error(KErrArgument, THA_KErrNoContentTypeDefined, &transmthd); RStringF contTypeStr = aStrPool.OpenFStringL(contTypeBuf); THTTPHdrVal contType(contTypeStr); aHeaders.SetFieldL(aStrPool.StringF(HTTP::EContentType, RHTTPSession::GetTable()), contType); contTypeStr.Close(); MHTTPDataSupplier *dataSupplier = this; iTransaction.Request().SetBody(*dataSupplier); return ETrue; }
//Invoke http method void CHttpClient::InvokeHttpMethodL(TInt aCommand) { RStringF method; iHasARequestBody = EFalse; if ( iConnectionManager && !iConnectionManager->IsOfflineMode()) { iConnectionManager->SetupConnection(); RStringPool strP = iConnectionManager->GetHTTPSession().StringPool(); switch (aCommand) { case CHttpConstants::EGet: method = strP.StringF(HTTP::EGET,RHTTPSession::GetTable()); break; case CHttpConstants::EPost: method = strP.StringF(HTTP::EPOST,RHTTPSession::GetTable()); iHasARequestBody = ETrue; break; default: return;//other commands not supported } //read body and url GetRequestBodyL(); TInt realSize = 0; for ( TInt i = 0; i < CHttpConstants::KMaxUrlSize && iUriPtr[i]; i++) { realSize++; } TBuf8<CHttpConstants::KMaxUrlSize> tmp; tmp.Copy(iUriPtr.Ptr(), realSize); tmp.ZeroTerminate(); TUriParser8 uri; uri.Parse(tmp); iTrans = iConnectionManager->GetHTTPSession().OpenTransactionL(uri, *iTransObs, method); RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection(); // Add headers appropriate to all methods SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent); SetHeaderL(hdr, HTTP::EAccept, KAccept); // Add headers and body data for methods that use request bodies if (iHasARequestBody) { // Content type header TBuf8<CHttpConstants::KMaxContentTypeSize> contTypeBuf; contTypeBuf.Copy(_L("text/html")); RStringF contTypeStr = iConnectionManager->GetHTTPSession().StringPool().OpenFStringL(contTypeBuf); THTTPHdrVal contType(contTypeStr); hdr.SetFieldL(iConnectionManager->GetHTTPSession().StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), contType); contTypeStr.Close(); MHTTPDataSupplier* dataSupplier = this; iTrans.Request().SetBody(*dataSupplier); } // submit the transaction iTrans.SubmitL(); // Start the scheduler, once the transaction completes or is cancelled on an error the scheduler will be // stopped in the event handler CActiveScheduler::Start(); //close and delete request file iReqBodyFile.Close(); iFileServ.Delete(iReqBodyFilePath); } }