PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Downloading file via Http Get

mehrozdurrani · 22 Jul 2010, 09:30 UTC
I need help and a proper method to download a file viz httpget request i ve tried the followin code but its not helping
Code:
ERESULT ClassMain::OnInit(ENATIVETYPE instance)
{

if (ecd.net[0]->Init(ECONN_SOCKET, this) == E_OK)
{

ClassEConsole::MsgWindow("Socket formed");
ecd.net[0]->SendHTTPGet("http://users.ugent.be/~bpuype/cgi-bin/fetch.pl?dl=wget/wget-1.9.1.exe");
ClassEConsole::MsgWindow("Server formed");
stack.Alloc(32768);
ClassEConsole::MsgWindow("test");


}
else
{
ClassEConsole::MsgWindow("Socket not formed");
}


return(E_OK);
}

Code:
void ClassMain::OnNetMessage(unsigned char connection, long id, long msg, long bufsize, unsigned char *buffer)
{
EHTTPRESPONSE_INFO info;
if (msg == ENET_SERVERFOUND)
{
ClassEConsole::MsgWindow("hi");
//The client has been connected
}

if (msg == ENET_RECEIVEDATA)
{
stack.Push(buffer, bufsize);
}

if(msg == ENET_CLOSEDSOCKET)
{
/*if (stack.GetResponseInfo(&info))
{*/
stack.GetResponseInfo(&info);

if(stack.BodySize() == 0)
{
unsigned char *bodydata = NULL;
unsigned long bodydatasize;
bodydata = (unsigned char *)ClassEMemory::Alloc(stack.BodySize());

if (bodydata != NULL)
{
stack.GetBody(bodydata, bodydatasize);
ClassEMemory::DeAlloc(bodydata);
}
//}
//}
stack.Clear();
}
}
}

tell me where m doin things wrong, i need a quick help
thanks in advance
Mehroz
Hi,

Are you saving the bodydata after the socket is closed? I don't see it in the sample you've posted which might explain why nothing is happening.