Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 6th, 2005, 7:07 AM   #1
amon
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 amon is on a distinguished road
Premature end of script headers

I had a quick search on the forum and couldn't find annother instance of this particular problem. i am new to doing cgi with c++ (i want to use some c++ libraries in my script). i have made a few shell scripts that work perfectly but i'm much of a noob with cgi.

I first started my full on programme which seemed to work perfectly going to the terminal and outpoutting to a text file which was opened with a web browser however i got this error so i copied an example from a book and got the same error.

I get the error from my server: Premature end of script headers

however when i ssh into the server and run the file directly i get the output:
Contenet-type: text/html

<HTML>
<BODY>
<H1>Hello Internet World</H1>
</BODY>
</HTML>

here is the code:
#include<iostream.h>
main()
{
	cout << "Contenet-type: text/html\n\n";
	cout << "<HTML>\n";
        cout << "<BODY>\n";
        cout << "<H1>Hello Internet World</H1>\n";
        cout << "</BODY>\n";
        cout << "</HTML>\n";
        cout << endl;
}

can someone tell me what i'm getting wrong i'm sure it is the simplest thing in the world that i'm missing (a sort of super n00b mistake).
amon is offline   Reply With Quote
Old May 6th, 2005, 8:12 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
For one thing, you can't spell "Content".
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 6th, 2005, 10:20 AM   #3
amon
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 amon is on a distinguished road
ok i corrected the spelling but the error prevails.
#include<iostream.h>
main()
{
	cout << "Content-type: text/html\n\n";
	cout << "<HTML>\n";
        cout << "<BODY>\n";
        cout << "<H1>Hello Internet World</H1>\n";
        cout << "</BODY>\n";
        cout << "</HTML>\n";
        cout << endl;
}
amon is offline   Reply With Quote
Old May 9th, 2005, 3:33 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
change it to this

#include <iostream> //no .h as its c++
using namespace std; //New Line

int main()
{
	cout << "Content-type: text/html\n\n";
	cout << "<HTML>\n";
        cout << "<BODY>\n";
        cout << "<H1>Hello Internet World</H1>\n";
        cout << "</BODY>\n";
        cout << "</HTML>\n";
        cout << endl;
        return 0;
}
Berto is offline   Reply With Quote
Old May 9th, 2005, 6:01 AM   #5
amon
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 amon is on a distinguished road
This is getting confusing, i made that change and the output is still the same from the server.

i have made an identical shell script which i run from the server using ssh. below is the code for each of the scripts and their outputs:
slink(282)$ more test.cpp
#include<iostream>
using namespace std;

main()
{
        cout << "Content-type: text/html\n\n";
        cout << "<HTML>\n";
        cout << "<BODY>\n";
        cout << "<H1>Hello Internet World</H1>\n";
        cout << "</BODY>\n";
        cout << "</HTML>\n";
        cout << endl;
}
//------------------------------------------------
// g++ test.cpp -o test.cgi
slink(283)$ more test2.cgi
#!/bin/bash
echo "Content-type: text/html"
echo
echo "<HTML>"
echo "<BODY>"
echo "<H1>Hello Internet World</H1>"
echo "</BODY>"
echo "</HTML>"
echo 
slink(284)$ ./test.cgi
Content-type: text/html

<HTML>
<BODY>
<H1>Hello Internet World</H1>
</BODY>
</HTML>

slink(285)$ ./test2.cgi
Content-type: text/html

<HTML>
<BODY>
<H1>Hello Internet World</H1>
</BODY>
</HTML>

The outputs i get when i access thease programmes with the webserver are confusing as both programes give the same output at the command line. the shell script works as intended but the c++ app still gives the "Premature end of script headers: test.cgi" error message
amon is offline   Reply With Quote
Old May 9th, 2005, 7:29 AM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Try adding a "Content-length" header... etc.

#include <iostream> //no .h as its c++
using namespace std; //New Line

int main()
{
        char *output;

	cout << "Content-type: text/html\n";

	strcpy(output, "<HTML>\n");
        strcat(output,  "<BODY>\n");
        strcat(output, "<H1>Hello Internet World</H1>\n");
        strcat(output, "</BODY>\n");
        strcat(output, "</HTML>\n");

        cout << "Content-length: " << strlen(output) <<  endl << endl;

        cout << output;
        cout << endl;

        return 0;
}
__________________

tempest is offline   Reply With Quote
Old May 11th, 2005, 6:33 AM   #7
amon
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 amon is on a distinguished road
i'm still getting the same errors after trying the new changes. is it possible for a servers settings to block cgi written in c++ but allow shell scripts?

could the output be being sent to the wrong place?
amon is offline   Reply With Quote
Old May 11th, 2005, 6:44 AM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
There's a point - are you running a local server, or using a host?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 11th, 2005, 8:02 AM   #9
amon
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 amon is on a distinguished road
i'm using a host, is there a way i can find out about what is and what isn't allowed?
amon is offline   Reply With Quote
Old May 11th, 2005, 8:37 AM   #10
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
paid for hosting it should have it if you goto the details about the package else e-mail them
Berto is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:58 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC