How to download the content of text file from URL in buffer

Login to reply to this topic.
Fri, 2008-02-15 06:05
Joined: 2007-07-31
Forum posts: 135

Hi everybody,

I want to download the text content from the following URL in the buffer using HTTP.

http://meragana.com/karaokedec.asp?scode=SAA1509W&akey=DEMOSAA1509W

How should i do that.Please give me a fully functional code.

I shall be very thnakfull to you... Smiling Smiling

I am using like this...

void CHTTPExampleEngine::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();
                        TInt DataSize=dataSupplier->OverallDataSize();
                        TPtrC8 ptr;
                        dataSupplier->GetNextDataPart(ptr);
                       
                        HBufC8* buf = HBufC8::NewLC(DataSize);
                        buf->Des().Copy(ptr);
       
                        pFile->WriteToFile(ptr); //heare we are writting the buffered data in the text file.
                       
                        dataSupplier->ReleaseData();
               
                        }
                        break;

                case THTTPEvent::EResponseComplete:
                        {
                       
                        }
                        break;
                       
                default:break;
               
                }
        }

Please help me asap...

Very very thanks in advance...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++


Fri, 2008-02-15 08:31
Joined: 2005-11-20
Forum posts: 1132
Re: How to download the content of text file from URL in buffer

I don't know where you got your sample code from, but I would recommend to study the HTTP example client, as you can find e.g. here:
http://www.symbiancodex.com/source/70sexamples/appprots/exampleclient/httpexampleclient.cpp.txt
(Good site, by the way, to search for sample code).

Just study carefully what this sample code does with iRespBodyFile, the file where everything received is written into.

You can see, for example, that for larger files your program will go through THTTPEvent::EGotResponseBodyData *several* times, each time for a chunk of the file, until the HTTP engine tells you that this was the last chunk. The OverallSize() method that you use is no good idea in a general case.

It's also a good idea to catch and treat THTTPEvent::ESucceeded and THTTPEvent::EFailed, because that's the way the HTTP engine tells you whether the whole transfer was a success or a failure. It can happen that you successfully receive three chunks and then slam into a THTTPEvent::EFailed because the connection to the server suddenly broke.


René Brunner

Sat, 2008-02-16 07:48
Joined: 2007-07-31
Forum posts: 135
Re: How to download the content of text file from URL in buffer

Actually when i run the HTTPExample application on machine it works correctly and dispaly the html text on the emulator screen.But when i run this example on my machine it doesnt work and shows the html text on the emulator screen.

when i debug the application the debugger doesnt come into the following function.

void CHTTPExampleEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
          switch (aEvent.iStatus)
                {
                case THTTPEvent::EGotResponseHeaders:
                break;
                case THTTPEvent::EGotResponseBodyData:
                {
                }

                }
}

Please give me some idea .What is the problem.

Thanks in advance.
Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Sat, 2008-02-16 08:46
Joined: 2005-11-20
Forum posts: 1132
Re: How to download the content of text file from URL in buffer

Well, no idea. If you took the HTTPExample code and start to change it to arrive at your code, there are probably a hundred things where you can go wrong and e.g. delete code that you think you don't need but in fact is essential.

Maybe study the unmodified HTTPExample code, until your really understand all of it, and then start again deriving your code from it? Might be unpleasant, sure, but still faster than finding the problem in your current code.

About debugging code that uses the Symbian HTTP classes: They seem to work so heavily with active objects that at least on my system it was not possible to set breakpoints, let them trigger, and then continue. The breakpoints triggered alright, but after that something with active objects, timing, timeouts, whatever, was so much disturbed by the break that it was not possible to continue program execution without producing the strangest errors afterwards.


René Brunner

  • Login to reply to this topic.