cgi question - WeOnlyDo Discussion board

cgi question (wodWebServer / wodWebServer.NET)

by ricado, Sunday, January 15, 2006, 22:45 (6679 days ago)

Could I call a cgi program by POST method?
The only example I could find in the sample file is:
User.Response.CGIExecute App.Path & MyCGI.bat
But how could I pass arguments to target program?
Thanks for your help!

Re: cgi question

by wodSupport, Sunday, January 15, 2006, 23:37 (6679 days ago) @ ricado

Yes you can. You should read from stdin in your cgi app to retrieve request body.

Re: cgi question

by ricado, Sunday, January 15, 2006, 23:52 (6679 days ago) @ wodSupport

Thanks for your quick response. The following is my html code which run on IIS 6.0. How could I go with wodWebServer?
[code]<html>

<head>

<title>Chat Example</title>

</head>

<body>

<script language= JavaScript >
<!--
function CheckForm ()
{
if (document.Chat.User.value == )
{
alert ( Please specify an user name! );
document.Chat.User.focus ();
}
else
document.Chat.submit ();
}
// -->
</script>

<form name= Chat action= http://localhost/cgi-bin/Chat.exe method= post >
Enter your name:&nbsp;
<input type= text name= User >&nbsp;
<input type= button value= Enter onclick= CheckForm () >
<input type= hidden name= Room value= Example >
<input type= hidden name= RefreshInterval value= 10 >
<input type= hidden name= MaxMessages value= 20 >
<input type= hidden name= Timeout value= 300 >
<input type= hidden name= ReturnFile value= / >
<input type= hidden name= StyleSheet value= Chat.ccs >
<input type= hidden name= Command value= Enter >
</form>

<script language= JavaScript >
<!--
document.Chat.User.focus ();
// -->
</script>

</body>

</html>
[/code]

Re: cgi question

by wodSupport, Monday, January 16, 2006, 22:16 (6678 days ago) @ ricado

Thanks for pointing out, I found out bug in wodWebServer. It should be fixed now. Can you please request update for wodWebServer, or download it again if you're evaluating it.

I didn't increate major version number yet, I will do it probably on next monday.

Your code should be as it was so far, such as [code]Private Sub Http1_RequestDone(ByVal User As WODWEBSERVERCOMLib.IWebUser)
If InStr(1, User.Request.URI, cgi-bin/Chat.exe ) Then
User.Response.CGIExecute yourcgi.exe
Else
User.Response.FileName = App.Path & \index.htm
End If
End Sub[/code]
and your CGI may look, for example, like this (C sample) [code] handle = open( output.txt , O_BINARY | O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
if (handle !=(-1))
{
lseek(handle, 0, SEEK_END);
while (gets(buff))
{
write(handle, buff, strlen(buff));
write(handle, \r\n , 2);
}
}
close(handle);

puts( Content-Type: text/html );
puts( );
printf( Done!\r\n , total);
[/code]

Let me know how it goes with new version

Kreso

Re: cgi question

by ricado, Tuesday, January 17, 2006, 16:29 (6677 days ago) @ wodSupport

Yes!
It does work!