Does LOCATION: http://  Work?

jujoo
jujoo used Ask the Experts™
on
I am using the following line in my CGI-PERL code:

print "Location: http://mywebsite.com/test.htm\n\n";

This is the ONLY line I have that outputs back to browser.  From what I've gathered, this should tell the browser to switch to this new web site (mywebsite.com/test.htm).  Unfortunately it doesn't do this.  

All I get is DOCUMENT CONTAINS NO DATA (or something to that extent) by Netscape 4.0 and down and MS Explorer.

Any clues as to what I'm doing wrong?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
Perhaps the http://mywebsite.com/test.htm document contains no data?
Or perhaps some other line in your program is preventing the only output line from printing.
Commented:
One more newline ought to do it (an HTTP header is delimited by a blank line).

BTW, I hope you're planning on increasing the points before grading this.

Commented:
Funny, looks like there's a blank line after the Location header to me...

jujoo, if you run the script from the commasd line what does it print? That might tell you something.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Commented:
Oops, I didn't look closely enough.  Now that I have, I see the real problem.  Try printing this:


"Location: http://mywebsite.com/test.htm\r\n\r\n"



You MUST use CR LF at the end of lines in HTTP.


Commented:
Must? I have never used \r\n and have seen only a handful of examples which do, almost everything I've seen uses just \n. I've never had a problem. (The server is repsonsible for parsing the headers anyway). Is this server-dependent?

Commented:
OK, "must" (especially with my all-caps emphasis) might have been a bit strong.  I meant it was in the HTTP spec as CR LF.

I beleive most servers see the LF coming in from a CGI and convert them to CR LF.

Could we get a URL to check so we can stop guessing here (and I can stop making bold statements that turn out to be wrong ;)


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial