I suspect this is basic, but how can I read a webpage with my MOD5234?
I see (and have made) all sorts of ways to serve webpages. I want to have my device get some parameters from the DSL modem at 192.168.1.1. Do I have to do an FTP?
Sam
Reading a webpage with Netburner?
Re: Reading a webpage with Netburner?
A web browser request to a server is basically a TCP connection and GET or POST request. You need two consecutive line feeds after the GET. There is an example of this in the NetBurner weather demo: http://demo.netburner.com:81/INDEX.HTM.
Re: Reading a webpage with Netburner?
I'm actually in the middle of generating some examples of this....
Here is a snipit of known workign code that does this...
Before you get to this code you need to have turned the name into an IP address
and put it in the ip variable
and put the text of the request into tRequest...
In this example the code that fills in the tRequest is here:
if(GetHostByName(pAddress,&ip,0,SLEEP_INTERVAL.tval())==DNS_OK)
{
iprintf("IP Address ="); ShowIP(ip);
siprintf(tRequest,"GET /%s?%s HTTP/1.1\r\nHost:%s\r\n\r\n",pUrl,DEVICENAME.string(),pAddress);
iprintf("Request =[%s]\r\n",tRequest);
}
else
{
LedState=LED_NO_DNS_RESOLVE;
iprintf("Failed to get DNS address\r\n");
}
//Now connect and get the result....
int fd=connect(ip,0,OUTBOUND_PORT.wval(),SLEEP_INTERVAL.tval());
if(fd<0)
{
LedState=LED_NO_SERVER_CONNECT;
ip=0;
}
else
{
LastConTime=TimeTick;
writestring(fd,tRequest);
int nread=0;
while(1)
{
int rv=ReadWithTimeout(fd,tResponse+nread,RESPONSE_SIZE-nread,REQUEST_TIMEOUT.tval());
if(bLog) iprintf("Read at %ld\r\n",TimeTick-LastStartTime);
if(rv>0)
{nread+=rv;
if(nread>=(RESPONSE_SIZE-1)) break;
tResponse[nread]=0;
}
else
break;
};
LastReadDoneTime=TimeTick;
if(nread)
{
nRequests++;
char * FindResult= strstr(tResponse,"\r\n\r\n");
if(FindResult)
{//Process the returned data
}
}
close(fd);
Here is a snipit of known workign code that does this...
Before you get to this code you need to have turned the name into an IP address
and put it in the ip variable
and put the text of the request into tRequest...
In this example the code that fills in the tRequest is here:
if(GetHostByName(pAddress,&ip,0,SLEEP_INTERVAL.tval())==DNS_OK)
{
iprintf("IP Address ="); ShowIP(ip);
siprintf(tRequest,"GET /%s?%s HTTP/1.1\r\nHost:%s\r\n\r\n",pUrl,DEVICENAME.string(),pAddress);
iprintf("Request =[%s]\r\n",tRequest);
}
else
{
LedState=LED_NO_DNS_RESOLVE;
iprintf("Failed to get DNS address\r\n");
}
//Now connect and get the result....
int fd=connect(ip,0,OUTBOUND_PORT.wval(),SLEEP_INTERVAL.tval());
if(fd<0)
{
LedState=LED_NO_SERVER_CONNECT;
ip=0;
}
else
{
LastConTime=TimeTick;
writestring(fd,tRequest);
int nread=0;
while(1)
{
int rv=ReadWithTimeout(fd,tResponse+nread,RESPONSE_SIZE-nread,REQUEST_TIMEOUT.tval());
if(bLog) iprintf("Read at %ld\r\n",TimeTick-LastStartTime);
if(rv>0)
{nread+=rv;
if(nread>=(RESPONSE_SIZE-1)) break;
tResponse[nread]=0;
}
else
break;
};
LastReadDoneTime=TimeTick;
if(nread)
{
nRequests++;
char * FindResult= strstr(tResponse,"\r\n\r\n");
if(FindResult)
{//Process the returned data
}
}
close(fd);
Re: Reading a webpage with Netburner?
Thanks, both are useful. Getting weather information was one of my objectives, I had forgotten about the demos.
Sam
Sam