View previous topic :: View next topic |
Author |
Message |
pgmarlin -
Joined: 06 Nov 2004 Posts: 2
|
Posted: Sat Nov 06, 2004 3:41 pm Post subject: 500 error: how do you return output to CGI? |
|
|
I wrote the following simple Foxpro program to execute as a CGI script
******************************************************************************
FUNCTION TestCGI
********** store 2 carriage return/line feeds ********
gcCRLF = CHR(13) + CHR(10)
******** store output string ***********
lcOut = "HTTP/1.0 200 OK" + gcCRLF + “Content-type: text/html”;
+ gcCRLF + gcCRLF ;
+ “<html>The current time is : “ + TIME() + “</html>“
********* copy output strint to text file *************
STRTOFILE(lcOut,”c:\ScriptOut.txt')
************* return output string to CGI ???? ***************
RETURN lcOut
******************************************************************************
In case you do not speak “Fox”, the program simply
1. Creates an output string variable that includes a header and html
2. Writes the string to a file C:\ScriptOut.txt
3. Retuns the string (hopefully to CGI for serving to the client)
Steps 1 and 2 ran properly and C:\ScriptOut.txt contained the following
---------------------------------------------------------------------------
HTTP/1.0 200 OK
Content-type: text/html
<html>The current time is : 23:18:53</html>
---------------------------------------------------------------------------
However, I received Error 500 - Internal Server Error
How do I get my output string back to STDOUT? If I write it to the screen (similar to DOS’s ECHO command), I still get the 500 error.
Thank you for any help you can give.
Paul Marlin |
|
Back to top |
|
|
admin Site Admin
Joined: 03 Mar 2002 Posts: 1300
|
Posted: Mon Nov 08, 2004 12:21 am Post subject: Re: 500 error: how do you return output to CGI? |
|
|
Your program should write the string to STDOUT in order to be CGI compliant.
But Error 500 can also happen for other reasons. For example, if Abyss is unable to run the CGI interpreter for some reason (usually, it is caused by PATH problems and missing DLLs.) |
|
Back to top |
|
|
pgmarlin -
Joined: 06 Nov 2004 Posts: 2
|
Posted: Tue Nov 09, 2004 2:18 am Post subject: |
|
|
Thank you for the response. Using the sample Visual Basic CGI program that I downloaded from the Abyss website, I determined that I have to use the Kernel32.dll in order to
1. get a file handle for Stdout using GETSTDHANDLE(-11)
2. write the output using WRITEFILE
and I was able to successfully translate the sample into Visual Foxpro and produce a web page.
NOW, can you suggest how to read the form variables (POST Method) from stdin? I tried using
1. GETSTDHANDLE(-10) and
2. READFILE
Both GETSTDHANDLE(-10) and READFILE returned zero.
The VB sample showed using -10& as the parameter for GETSTDHANDLE, but I don’t know what “&” is, since it is not used in Visual Foxpro.
Incidently the dll declarations I used were
DECLARE long GetStdHandle IN kernel32.dll long handleInput
DECLARE long ReadFile IN kernel32.dll ;
long filehandle, string buffer,;
long BytesToRead, long @ BytesRead, long OptionalPar
DECLARE long WriteFile IN kernel32.dll ;
long filehandle, string buffer, long BytesToWrite, ;
long @ BytesWritten
the successful write command was
WRITEFile(lnOutputHandle, lcOutString, LEN(lcOutString), lnBytesWritten)
(I did not have to use the optional 5th parameter)
The unsuccessful read commands were
lcBuffer = SPACE(5000)
lnRead = 0
lnResult = READFILE(lnInputHandle, lcBuffer, 5000,lnRead,0)
The fith parameter was not optional; if I omitted it, I got an “exception” error.
Incidently, is there any chance that the web server creates a temporary file from stdin that i could read?
Any help would be appreciated. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|