[En-Nut-Discussion] browser redirection with "Location:"

Dave Smart Dave at Smart-Family.net
Sat Dec 13 02:35:57 CET 2003


I have a web page compiled into the file system which I based on the httpd
sample - the many samples are terrific by the way!

I proved by example on my PC web server that -
	print <<"EOM";
	Location: http://192.168.1.101/HWTest.htm

	EOM
	exit;
will take me from the home PC to my Ethernut web server, as expected. I
wanted to do something similar within the ethernut site, but can't get this
method to work, and I'm not sure why.

Eventually, the fixed page in this example will be selected based on the cgi
parameters. I thought about opening the file of interest and sending it
directly, but having both my code and the server code doing the same thing
seemed wasteful, so I thought it more elegant to use the browser redirection
and let the server open and send the file.

In more detail -

On one of my web pages I configured several hardware tests, so there are
links similar to <http://192.168.1.101/cgi-bin/test.cgi?Sound=Tone1>, where
the ip is that of the ethernut web server.

When I click on this link, it is handled just as it should (even makes the
noise it should). I then want it to refresh to the web page it came from, so
I may activate another of the tests. This is where I'm stuck.

I tried several variations of -

static prog_char redirect[] = "Location: http://%s/HWTest.htm\r\n\r\n";

Like this -
    NutHttpSendHeaderTop(stream, req, 200, "Ok");
    NutHttpSendHeaderBot(stream, html_mt, -1);
    fprintf_P(stream, redirect1, inet_ntoa(confnet.cdn_ip_addr));

and even this hardwired version -

    fputs_P("Location: http://192.168.1.101/HWTest.htm\r\n\r\n", stream);

I did finally get it to work the round-about way -

static prog_char redirect[] = "<html><meta http-equiv=\"Refresh\"
content=\"0;URL=http://%s/HWTest.htm\"></head><body>Back to
test.</body></html>";

but it sits on this screen long enought to anoy me.

Can you see what I'm doing wrong?

Dave Smart





More information about the En-Nut-Discussion mailing list