// --------------------------------------------------------------------------- // Response received // --------------------------------------------------------------------------- // TBool CCatalogsHttpTransaction::ResponseReceived( TInt aResponseStatusCode, const TDesC8& aResponseStatusText ) { DLTRACEIN(( "%d, text: %S", aResponseStatusCode, &aResponseStatusText )); iResponseStatusCode = aResponseStatusCode; iResponseStatusText = aResponseStatusText.Alloc(); if ( !iResponseStatusText ) { return HandleHttpError( ECatalogsHttpErrorGeneral, KErrNoMemory ); } if ( aResponseStatusCode >= 400 ) { iState.iOperationState = ECatalogsHttpOpFailed; return iObserver->HandleHttpError( *this, TCatalogsHttpError( ECatalogsHttpErrorHttp, KCatalogsErrorHttpBase - aResponseStatusCode ) ); } else { iState.iOperationState = ECatalogsHttpOpInProgress; iState.iProgressState = ECatalogsHttpConnected; NotifyObserver(); } DLTRACEOUT(("")); return EFalse; }
// --------------------------------------------------------------------------- // Received a response header // --------------------------------------------------------------------------- // void CCatalogsHttpTransaction::ResponseHeaderReceived( const TDesC8& aHeader, const TDesC8& aValue ) { DLTRACEIN( ("") ); DASSERT( iObserver ); TRAPD( err, iResponseHeaders->AddHeaderL( aHeader, aValue ) ); if ( err != KErrNone ) { HandleHttpError( ECatalogsHttpErrorGeneral, err ); return; } iState.iOperationState = ECatalogsHttpOpInProgress; iState.iProgressState = ECatalogsHttpResponseHeaderReceived; if ( aHeader.CompareF( KHttpContentRangeHeader ) == 0 ) { // // Content-Range, bytes x-y/z // Extract 'z' and use it as the total content length // TPtrC8 ptr( aValue ); TInt offset = ptr.Locate( '/' ); if ( offset != KErrNotFound ) { TLex8 val; val.Assign( ptr.Mid( offset + 1 ) ); TInt value; TInt err = val.Val( value ); if ( err == KErrNone ) { iContentLength = value; DLTRACE(( "Content length: %i", iContentLength )); } } } else if ( aHeader.CompareF( KHttpContentLengthHeader ) == 0 ) { // // If content length for this request has not been already set // e.g. from a Content-Range header, extract from Content-Length header // if ( iContentLength == 0 ) { TLex8 val; val.Assign( aValue ); TInt value; TInt err = val.Val( value ); if ( err == KErrNone ) { iContentLength = value; DLTRACE(( "Content length: %i", iContentLength )); } } else { DLTRACE(( "-> ContentLength set, ignoring" )); } } else if ( aHeader.CompareF( KHttpContentTypeHeader ) == 0 ) { // Content type from the header DLTRACE( ( "Content type received" ) ); TRAPD( err, SetContentTypeL( aValue ) ); if ( err != KErrNone ) { DLTRACE( ( "Content type setting failed with err: %i", err ) ); HandleHttpError( ECatalogsHttpErrorGeneral, err ); return; } else { iState.iProgressState = ECatalogsHttpContentTypeReceived; } } // Report the observer that a header has been received NotifyObserver(); }
void TeamWorkApi::IssueRequest( QString strUrl, QString strData ){ strCurrentRequest.clear(); QNetworkRequest objRequest = CreateRequestObject( strUrl ); if( 0 < strData.length() ) pobjReply = objNetwork.post( objRequest, strData.toAscii() ); else pobjReply = objNetwork.get( objRequest ); QObject::connect( pobjReply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( HandleHttpError( QNetworkReply::NetworkError ) ) ); QObject::connect( pobjReply, SIGNAL( finished() ), this, SLOT( RequestFinished() ) ); QObject::connect( pobjReply, SIGNAL( readyRead() ), this, SLOT( ReadHttpData() ) ); }