×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    6

    Smile Http request/response problem

    Hi,

    I am very new in symbian c++.I am working in s60 2d edition.i have dowloaded s60 platform http client API example from forum nokia.http post/get works fine earlier. now http post is working after posting the connecting message displayed but response page from server not received. i received this error no -5120(when i gave this url http://www.google.com),i received this error no -5105(when i gave this url http://localhost ).pls help me last one week i am struggled this problem.

    pls reply for this id mrekha01@gmail.com

    here i post my clientengine code:


    #include <avkon.hrh>
    #include <aknnotewrappers.h>
    #include <uri8.h>
    #include <http.h>
    #include <chttpformencoder.h>
    #include <HttpStringConstants.h>
    #include <http\RHTTPTransaction.h>
    #include <http\RHTTPSession.h>
    #include <http\RHTTPHeaders.h>
    #include <HTTPClientExample.rsg>

    #include <COMMDB.H>
    #include <CDBPREFTABLE.H>
    #include <CommDbConnPref.h>

    #include "Client.pan"
    #include "Client.hrh"
    #include "ClientEngine.h"

    _LIT8(KUserAgent, "SimpleClient 1.0");

    _LIT8(KAccept, "*/*");

    const TInt KStatustextBufferSize = 32;
    const TInt KInfotextBufferSize = 64;
    const TInt KURIBufferSize = 128;
    const TInt KDefaultBufferSize = 256;

    CClientEngine* CClientEngine::NewL(MClientObserver& aObserver)
    {
    CClientEngine* self = CClientEngine::NewLC(aObserver);
    CleanupStack::Pop(self);
    return self;
    }

    CClientEngine* CClientEngine::NewLC(MClientObserver& aObserver)
    {
    CClientEngine* self = new (ELeave) CClientEngine(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

    CClientEngine::CClientEngine(MClientObserver& aObserver)
    : iObserver(aObserver),
    iPostData(NULL),
    iRunning(EFalse)
    {
    }

    CClientEngine::~CClientEngine()
    {
    iSession.Close();
    iConnection.Close();
    iSocketServ.Close();

    delete iPostData;
    }

    void CClientEngine::ConstructL()
    {

    TRAPD(err, iSession.OpenL());
    if(err != KErrNone)
    {

    _LIT(KErrMsg,"Cannot create session. Is internet access point configured?");
    _LIT(KExitingApp, "Exiting app.");
    CEikonEnv::Static()->InfoWinL(KErrMsg, KExitingApp);
    User::Leave(err);
    }

    InstallAuthenticationL(iSession);

    }

    void CClientEngine::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
    {
    RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
    CleanupClosePushL(valStr);
    THTTPHdrVal val(valStr);
    aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,
    RHTTPSession::GetTable()), val);
    CleanupStack::PopAndDestroy();
    }

    void CClientEngine::IssueHTTPGetL(const TDesC8& aUri)
    {
    SetupConnectionL();

    TUriParser8 uri;
    uri.Parse(aUri);

    RStringF method = iSession.StringPool().StringF(HTTP::EGET,
    RHTTPSession::GetTable());

    iTransaction = iSession.OpenTransactionL(uri, *this, method);

    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    SetHeaderL(hdr, HTTP::EAccept, KAccept);

    iTransaction.SubmitL();

    iRunning = ETrue;
    _LIT(KConnecting,"Connecting...");
    iObserver.ClientEvent(KConnecting);
    }

    void CClientEngine::IssueHTTPPostL(const TDesC8& aUri,
    const TDesC8& aContentType,
    const TDesC8& aBody)
    {
    SetupConnectionL();

    TUriParser8 uri;
    uri.Parse(aUri);

    delete iPostData;
    iPostData = aBody.AllocL();

    RStringF method = iSession.StringPool().StringF(HTTP::EPOST,
    RHTTPSession::GetTable());

    iTransaction = iSession.OpenTransactionL(uri, *this, method);

    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    SetHeaderL(hdr, HTTP::EAccept, KAccept);
    SetHeaderL(hdr, HTTP::EContentType, aContentType);

    MHTTPDataSupplier* dataSupplier = this;
    iTransaction.Request().SetBody(*dataSupplier);

    iTransaction.SubmitL();

    iRunning = ETrue;
    _LIT(KConnecting,"Connecting...");
    iObserver.ClientEvent(KConnecting);
    }

    void CClientEngine::CancelTransaction()
    {
    if(!iRunning)
    return;

    iTransaction.Close();

    iRunning = EFalse;
    _LIT(KTransactionCancelled, "Transaction cancelled");
    iObserver.ClientEvent(KTransactionCancelled);
    }

    void CClientEngine::MHFRunL(RHTTPTransaction aTransaction,
    const THTTPEvent& aEvent)
    {
    switch (aEvent.iStatus)
    {
    case THTTPEvent::EGotResponseHeaders:
    {

    RHTTPResponse resp = aTransaction.Response();
    TInt status = resp.StatusCode();

    TBuf<KStatustextBufferSize> statusText;
    statusText.Copy(resp.StatusText().DesC());

    TBuf<KDefaultBufferSize> text;
    _LIT(KHeaderReceived, "Header received. Status: %d %S");
    text.Format(KHeaderReceived, status, &statusText);
    iObserver.ClientEvent(text);
    }
    break;

    case THTTPEvent::EGotResponseBodyData:
    MHTTPDataSupplier* body = aTransaction.Response().Body();
    TPtrC8 dataChunk;
    TBool isLast = body->GetNextDataPart(dataChunk);
    iObserver.ClientBodyReceived(dataChunk);

    TBuf<KInfotextBufferSize> text;
    _LIT(KBodyPartReceived, "%d bytes received... ");
    text.Format(KBodyPartReceived, dataChunk.Length());
    iObserver.ClientEvent(text);

    if (isLast)
    {
    _LIT(KBodyReceived,"Body received");
    iObserver.ClientEvent(KBodyReceived);
    }

    body->ReleaseData();
    }
    break;

    case THTTPEvent::EResponseComplete:
    {
    _LIT(KTransactionComplete, "Transaction Complete");
    iObserver.ClientEvent(KTransactionComplete);
    }
    break;

    case THTTPEvent::ESucceeded:
    {
    _LIT(KTransactionSuccessful, "Transaction Successful");
    iObserver.ClientEvent(KTransactionSuccessful);

    aTransaction.Close();
    iRunning = EFalse;
    }
    break;

    case THTTPEvent::EFailed:
    {
    _LIT(KTransactionFailed, "Transaction Failed");
    iObserver.ClientEvent(KTransactionFailed);
    aTransaction.Close();
    iRunning = EFalse;
    }
    break;

    default:

    {
    TBuf<KInfotextBufferSize> text;
    if (aEvent.iStatus < 0)
    {
    _LIT(KErrorStr, "Error: %d");
    text.Format(KErrorStr, aEvent.iStatus); aTransaction.Close();
    iRunning = EFalse;
    }
    else
    {
    _LIT(KUnrecognisedEvent, "Unrecognised event: %d");
    text.Format(KUnrecognisedEvent, aEvent.iStatus);
    }
    iObserver.ClientEvent(text);
    }
    break;
    }
    }

    TInt CClientEngine::MHFRunError(TInt aError,
    RHTTPTransaction /*aTransaction*/,
    const THTTPEvent& /*aEvent*/)
    {
    TBuf<KInfotextBufferSize> text;
    _LIT(KRunError, "MHFRunError: %d");
    text.Format(KRunError, aError);
    iObserver.ClientEvent(text);
    return KErrNone;
    }

    TBool CClientEngine::GetNextDataPart(TPtrC8& aDataPart)
    {
    if(iPostData)
    {
    aDataPart.Set(iPostData->Des());
    }
    return ETrue;
    }
    void CClientEngine::ReleaseData()
    {
    delete iPostData;
    iPostData = NULL;
    }

    TInt CClientEngine::Reset()
    {
    return KErrNone;
    }

    TInt CClientEngine::OverallDataSize()
    {
    if(iPostData)
    return iPostData->Length();
    else
    return KErrNotFound ;
    }

    TBool CClientEngine::GetCredentialsL(const TUriC8& aURI,
    RString aRealm,
    RStringF aAuthenticationType,
    RString& aUsername,
    RString& aPassword)
    {
    TBuf<KURIBufferSize> authType;
    TBuf<KURIBufferSize> uri;
    TBuf<KDefaultBufferSize> authText;
    authType.Copy(aAuthenticationType.DesC());
    uri.Copy(aURI.UriDes());
    _LIT(KAuthRequired, "%S requires %S authentication.");
    authText.Format(KAuthRequired, &uri, &authType);
    _LIT(KAuthNote, "Authentication required.");
    CEikonEnv::Static()->InfoWinL(KAuthNote, authText);

    TBuf<KDefaultBufferSize> userName;
    TBuf<KDefaultBufferSize> password;
    CAknMultiLineDataQueryDialog* dlg =
    CAknMultiLineDataQueryDialog::NewL(userName, password);

    if (!dlg->ExecuteLD(R_DIALOG_USER_PASSWORD_QUERY))
    return EFalse; // No credentials given; must return EFalse

    TBuf8<KDefaultBufferSize> temp;
    temp.Copy(userName);
    TRAPD(err, aUsername = aRealm.Pool().OpenStringL(temp));
    if (!err)
    {
    temp.Copy(password);
    TRAP(err, aPassword = aRealm.Pool().OpenStringL(temp));
    if (!err) return ETrue;
    }

    return EFalse;
    }

    void CClientEngine::SetupConnectionL()
    {
    if( iConnectionSetupDone )
    return;

    iConnectionSetupDone = ETrue;

    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));

    CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
    CleanupStack::PushL(commDB);

    CCommsDbConnectionPrefTableView* commDBView =
    commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown);

    User::LeaveIfError(commDBView->GotoFirstRecord());

    CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;

    commDBView->ReadConnectionPreferenceL(pref);
    TUint32 iapID = pref.iBearer.iIapId;

    CleanupStack::PopAndDestroy(commDBView);

    CleanupStack::PopAndDestroy(commDB);
    TCommDbConnPref connectPref;

    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connectPref.SetDirection(ECommDbConnectionDirectionUnknown);
    connectPref.SetBearerSet(ECommDbBearerGPRS);
    connectPref.SetIapId(iapID);

    User::LeaveIfError(iConnection.Start(connectPref));

    RStringPool strPool = iSession.StringPool();
    RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();

    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );

    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ),
    THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) );
    }

    // end of file

    By
    Rekha

  2. #2
    Regular Contributor
    Join Date
    Jun 2004
    Location
    Helsinki, Finland
    Posts
    69

    Re: Http request/response problem

    If you are using emulator, try using IP-address instead of a name of a site.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    6

    Re: Http request/response problem

    Quote Originally Posted by myohol
    If you are using emulator, try using IP-address instead of a name of a site.
    Thanks for ur replay,

    but i have changed in my emulator settings ip address and DNS server also. afterthat the same error -5120 is displayed. ip and DNS server same as system ip and DNS server.Any one tell me how to solve this problem.

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Http request/response problem

    That error code means no IP route available.

    With the emulator you can't just run it and it will automatically be able to make a connection, various things have to be configured first. If you browse the symbian papers on the Nokia site or google for words like configuring emulator internet etc. you should find some documents describing what to do.

Similar Threads

  1. access points problem with HTTP client api
    By Svat_ in forum Symbian
    Replies: 1
    Last Post: 2006-12-26, 16:19
  2. Problem in Http Connection
    By jaceline in forum Mobile Java General
    Replies: 0
    Last Post: 2005-10-14, 04:08
  3. NOKIA vs. SIEMENS HTTP connection problem?
    By imarenic in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-11-03, 09:03
  4. multi-thread problem for HTTP connection
    By homanshing in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-09-17, 16:07
  5. Replies: 2
    Last Post: 2003-02-19, 03:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×