Exemplo n.º 1
0
// ----------------------------------------------------------------------------
// CClientEngine::IssueHTTPGetL()
//
// Start a new HTTP GET transaction.
// ----------------------------------------------------------------------------
void CClientEngine::IssueHTTPGetL(const TDesC8& aUri)
	{
	SetupConnectionL();	
		
	// Parse string to URI (as defined in RFC2396)
	TUriParser8 uri;
	uri.Parse(aUri);

	// Get request method string for HTTP GET
	RStringF method = iSession.StringPool().StringF(HTTP::EGET,
		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 and accepted content type
	RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
	SetHeaderL(hdr, HTTP::EAccept, KAccept);

	// Submit the transaction. After this the framework will give transaction
	// events via MHFRunL and MHFRunError.
	iTransaction.SubmitL();

	iRunning = ETrue;
	_LIT(KConnecting,"Connecting...");
	iObserver.ClientEvent(KConnecting);
	}
void UPPayHttpConnection::ReGetRequestL()
{
	iContentLength = 0;
	AddTimer();
	
	SetupConnectionL();
	sendRequest();
}
void UPPayHttpConnection::GetRequestL(const TDesC& aUri, TInt aStartPos)
{
	iContentStartPos = aStartPos;
	iContentLength = 0;
	iStatusCode = -1;
	//CommonUtils::WriteLogL(_L("F_HttpConnection::GetRequestL:"), aUri);
	iIsGetMethod = ETrue;
	ParseUriL(aUri);
	AddTimer();
	
	SetupConnectionL();

}
void UPPayHttpConnection::PostRequestL(const TDesC& aUri, const TUint8 * aPostData, TInt aDataLen)
{
	iContentStartPos = 0;
	iContentLength = 0;
	iStatusCode = -1;
	if (aPostData && aDataLen > 0)
	{
		iPostData = new char[aDataLen];
		iPostDataLength = aDataLen;
		iCurPostDataLength = aDataLen;
		Mem::Copy(iPostData, aPostData, aDataLen);
		iIsGetMethod = EFalse;
	}
	//CommonUtils::WriteLogL(_L("F_HttpConnection::PostRequestL:"), aUri);
	//CommonUtils::WriteLogL(_L("F_HttpConnection::PostRequestL:"), aDataLen);
	ParseUriL(aUri);
	AddTimer();
	
	SetupConnectionL();
}
TBool CommonSocketConnection::OpenConnection()
{
	switch(iConnectionState)
	{
		case EConnecting:
			return EFalse;
			break;
		case EConnected:
		{
			TUint iConnectionCount = 0;
			iConnection.EnumerateConnections(iConnectionCount);
			if (iConnectionCount>0)
			{
				return ETrue;
			}
			else
			{
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection start");
#endif	
				SetupConnectionL();
				if(!iWait.IsStarted())
				iWait.Start();
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection iWait end");
#endif	
				if(iConnectionState==EConnected)
				{
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection iConnectionState==EConnected");
#endif	
//					if(iMonitor)
//					{
//						delete iMonitor;
//						iMonitor = NULL;
//					}
					iMonitor = CConnMon::NewL(iConnection,iSocketServ,*this);
					iMonitor->Start();
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection return  true");
#endif	
					return ETrue;
				}
				else
				{
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection delete iMonitor ");
#endif	
//					if(iMonitor)
//					{
//						delete iMonitor;
//						iMonitor = NULL;
//					}
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection return  false");
#endif	
					return EFalse;
				}			
			}		
			break;
		}
		case ENotConnected:
		{

#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection start2");
#endif	
				SetupConnectionL();
				if(!iWait.IsStarted())
				iWait.Start();
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection iWait end2");
#endif	
				if(iConnectionState==EConnected)
				{
//					if(iMonitor)
//					{
//						delete iMonitor;
//						iMonitor = NULL;
//					}
					iMonitor = CConnMon::NewL(iConnection,iSocketServ,*this);
					iMonitor->Start();
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection return  true2");
#endif	
					return ETrue;
				}
				else
				{
#ifdef XF_DEBUG_HTTP
		XF_IO_printf("________________CommonHttpConnection OpenConnection return  false2");
#endif	
					return EFalse;
				}			
			break;
		}
		default:
		{
			return EFalse;
			break;
		}
	}
}