![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
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). |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
For one thing, you can't spell "Content".
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
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;
} |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
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;
} |
|
|
|
|
|
#5 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
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;
}
__________________
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
There's a point - are you running a local server, or using a host?
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
i'm using a host, is there a way i can find out about what is and what isn't allowed?
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() |
paid for hosting it should have it if you goto the details about the package else e-mail them
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|