×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Arrow trouble retrieving webpage

    Hey

    Carbide.c++ 1.2.2
    SDK S60 3rd 1fp

    I'm trying to get an symbian application to retrieve a webpage on the internet. But it fails to do so...

    When I run my code on the emulator then the app retrieve the webpage, but when I run it on my N95 nothing happens. After choosing web access point on the N95 device, I wait about 1 minute and nothing have been retrieved.. So maybe it's because of slow connection, but N95 is 3G...

    When choosing Web Access Point I had 3 options to choose from:
    - Telenor
    - Telenor Internet
    - Telenor MMS
    (I've been choosing Telenor and Telenor Internet)... Another important info to add here is that instantly after selecting web access point the device ask again for web access point (it displays the same options again) and I again have to choose my web access point... After doing this last selection nothing happens. I wait for about 1 minute and nothing have been retrieved.. (it is a simple webpage I try to download, with only about 10 people visits every day... so the load on it's webserver isn't much)

    Well here I post the code which the app use to connect to internet (In this code I've marked an area with bold text, this is an CAknInformationNote which is displayed on my N95 when app tryes to connect to internet - the CAknInformationNote gives debug info, it tells that the app atleast executed this):

    any suggestions why my app don't retrieve the webpage is greatly welcome.

    #include "NetEngine.h"
    #include "TestAppUi.h"
    #include <httpstringconstants.h>
    #include <rhttpheaders.h>
    #include <stringpool.h>
    #include <stringloader.h>
    #include <thttphdrval.h>
    #include <aknnotewrappers.h>

    #include <TestApp_0xEB1E9A4B.rsg>

    _LIT8(KUserAgent, "HTTPExample (1.0)"); // Name of this client app
    _LIT8(KAccept, "text/*");

    CNetEngine* CNetEngine::NewL(MNetEngineObserver& aObserver)
    {
    CNetEngine* self = new (ELeave) CNetEngine(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
    }


    CNetEngine::CNetEngine(MNetEngineObserver& aObserver) : iObserver(aObserver)
    {

    }

    void CNetEngine::ParseUriL(const TDesC& aUri)
    {
    // Convert the URI to an 8-bit descriptor
    // then set iUriParser to point at it
    delete iUri;
    iUri = NULL;
    iUri = HBufC8::NewL(aUri.Length());
    iUri->Des().Copy(aUri);
    User::LeaveIfError(iUriParser.Parse(*iUri));
    }

    void CNetEngine::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( &valStr );

    }

    void CNetEngine::GetRequestL(const TDesC& aUri)
    {
    // Parse the URI
    ParseUriL(aUri);

    _LIT(KTxtConsoleTitle, "iSession.OpenTransactionL");
    CAknInformationNote* note = new (ELeave) CAknInformationNote;
    note->ExecuteLD(KTxtConsoleTitle);


    // Create the transaction
    iTransaction = iSession.OpenTransactionL(iUriParser, *this,
    iSession.StringPool().StringF(HTTP::EGET, RHTTPSession::GetTable()));

    // Set transaction headers
    RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();
    SetHeaderL(headers, HTTP::EUserAgent, KUserAgent);
    SetHeaderL(headers, HTTP::EAccept, KAccept);

    // Submit the request
    iTransaction.SubmitL();

    _LIT(KTxtConsoleTitle2, "iTransaction.SubmitL");
    CAknInformationNote* note1 = new (ELeave) CAknInformationNote;
    note1->ExecuteLD(KTxtConsoleTitle2);

    }



    void CNetEngine::ConstructL()
    {
    TRAPD( err, iSession.OpenL() );
    if (err != KErrNone)
    {
    HBufC* textResource = StringLoader::LoadLC( R_CONNECTING_ERROR, err );
    CAknErrorNote* errorNote;
    errorNote = new (ELeave) CAknErrorNote;
    errorNote->ExecuteLD( *textResource );
    CleanupStack::PopAndDestroy( textResource );
    User::Leave( err );

    }
    }

    CNetEngine::~CNetEngine()
    {
    iTransaction.Close();
    iSession.Close();
    delete iResponseBuffer;
    delete iUri;
    }

    TInt CNetEngine::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
    {

    HBufC* textResource = StringLoader::LoadLC( R_CONNECTING_ERROR, aError );
    CAknErrorNote* errorNote;
    errorNote = new (ELeave) CAknErrorNote;
    errorNote->ExecuteLD( *textResource );
    CleanupStack::PopAndDestroy( textResource );
    User::Leave( aError );

    return aError;
    }


    void CNetEngine::CancelTransactionL()
    {
    if( !iRunning )
    return;

    iTransaction.Close();

    // Not running anymore
    iRunning = EFalse;

    }

    void CNetEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
    {
    switch (aEvent.iStatus)
    {
    case THTTPEvent::EGotResponseHeaders:
    {
    // HTTP response headers have been received.
    // Pass status information to observer.
    RHTTPResponse resp = aTransaction.Response();

    // Get status code
    TInt statusCode = resp.StatusCode();

    // Get status text
    RStringF statusStr = resp.StatusText();
    HBufC* statusBuf = HBufC::NewLC(statusStr.DesC().Length());
    statusBuf->Des().Copy(statusStr.DesC());

    // Inform observer
    iObserver.ResponseStatusL(statusCode, *statusBuf);

    CleanupStack::PopAndDestroy(statusBuf);
    }
    break;


    case THTTPEvent::EGotResponseBodyData:
    {
    // Get text of response body
    MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body();
    TPtrC8 ptr;
    dataSupplier->GetNextDataPart(ptr);

    // Convert to 16-bit descriptor
    HBufC* buf = HBufC::NewLC(ptr.Length());
    buf->Des().Copy(ptr);

    // Append to iResponseBuffer
    if (!iResponseBuffer)
    {
    iResponseBuffer = buf->AllocL();
    }
    else
    {
    iResponseBuffer = iResponseBuffer->ReAllocL(iResponseBuffer->Length() + buf->Length());
    iResponseBuffer->Des().Append(*buf);
    }

    // Release buf
    CleanupStack::PopAndDestroy(buf);

    // Release the body data
    dataSupplier->ReleaseData();
    }
    break;

    case THTTPEvent::EResponseComplete:
    {
    // Pass the response buffer by reference to the observer
    iObserver.ResponseReceivedL(*iResponseBuffer);
    }
    break;
    }
    }

  2. #2
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985

    Re: trouble retrieving webpage

    Just a stupid suggestion: have you checked whether other applications are able to connect to the Internet? For example, you can try Web browser.

    Also, have you tried using WiFi, instead of 3G network?
    Antony Pranata
    http://www.antonypranata.com/
    http://www.s60tips.com/

  3. #3
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Re: trouble retrieving webpage

    Thanks for responding to my post

    Yes other applications on my N95 can connect to internet. I can for example use the embedded web browser to view pages.

    I've also used WiFi, but not on this scenario here. The reason I haven't used it is because I don't have WiFi. I tryed surfing using WiFi at a pub a few months ago (using the standard web browser on N95).

    Could it be because the phone is locked to Telenor mobile company and the phone is set to refuse webpages created by others than Telenor. I doubt this, but anyway just a thought I have. I think the mobile companies do what they can to have total control over the device...

  4. #4
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985

    Re: trouble retrieving webpage

    According to your information you see the dialog "iTransaction.SubmitL"; so it means GetRequestL() didn't leave? Is MHFRunL() or MHFError() got called after a while?
    Antony Pranata
    http://www.antonypranata.com/
    http://www.s60tips.com/

  5. #5
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Re: trouble retrieving webpage

    I see that MHFRunL() get executed. I've put an CAknInformationNote inside it. For a very short moment it displays a negativ number. But almost instantly changed to the value 9 (THTTPEvent.iStatus)...

    I think the negativ number is -46 or maybe - 49, it happens so fast that I don't see it properly

    What event is THTTPEvent.iStatus??

  6. #6
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985

    Re: trouble retrieving webpage

    I think it should be -46 (KPermissionDenied).

    Have you checked the capabilities your application? You would need "NetworkServices" to access the Internet from your application.

    PS: Also consider using RFileLogger to output a log file to the phone memory. It is easier to trace your application; rather than using CAknInformationNote.
    Antony Pranata
    http://www.antonypranata.com/
    http://www.s60tips.com/

  7. #7
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Re: trouble retrieving webpage

    thanks for that tip. I'm a newbie in Symbian, so I haven't used RFileLogger before but I will check it out

    What capability do I have to add to this app so it can access internet? in .mmp I can add NetworkService but is there some other capabilities I also need to add??

  8. #8
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Re: trouble retrieving webpage

    I've solved it. I added NetworkService to the app and it can connect to internet

  9. #9
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985

    Re: trouble retrieving webpage

    You should be able to find the required capabilities from the SDK Help. Normally there is something like "Capability: NetworkServices".

    Alternatively, you can also run your application in the emulator by enabling EPOCWIND.OUT (from Tools | Preferences). Then check your EPOCWIND.OUT to check whether your application is missing capability or not. Search of PlatSec error message.
    Antony Pranata
    http://www.antonypranata.com/
    http://www.s60tips.com/

Similar Threads

  1. Nokia PCSuite setup trouble: the ultimate solution?
    By surfmaxx in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2006-10-04, 09:52
  2. Webpage fetch using WWW, MMS IAP
    By indvin in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-01-12, 13:21
  3. Replies: 0
    Last Post: 2002-07-16, 05:32

Posting Permissions

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