[UE] Exact data not getting on the browser
Added by syedr1 about 1 month ago
Hi All,
Iam currently working on lighttpd with fast cgi support.When I send the data to browser, it contains all the data including printf , ELF etc as shown in attached image lighttpd-fastcgi.JPG
Added mod_fastcgi in lighttpd.conf file
server.modules += ( "mod_compress", "mod_dirlisting", "mod_fastcgi", "mod_staticfile", )
Installed below packages:sudo apt install lighttpd
sudo apt-get install libfcgi-dev
My C code is as below
int main() { while (FCGI_Accept() >= 0) { char* content = getenv("QUERY_STRING"); printf("#########################################\n"); if (content != NULL) { double number; if (sscanf(content, "number=%lf", &number) == 1) { double square = number * number; printf("square11111111111 = %d\n",square); printf("Content-type: text/plain\r\n\r\n%.2f", square); } } } return 0; }
My HTML code is as below
<!DOCTYPE html> <html> <head> <title>Square Calculator</title> </head> <body> <h1>Calculate the Square of a Number</h1> <p>Enter a number: <input type="text" id="numberInput"></p> <button onclick="calculateSquare()">Calculate</button> <p>Square: <span id="squareValue"></span></p> <script> function calculateSquare() { const number = document.getElementById("numberInput").value; fetch('/square_cgi?number=' + number) .then(response => response.text()) .then(data => { document.getElementById("squareValue").textContent = data; }); } </script> </body> </html>
Please let me know How I ca only get square value on the browswer instead of all html data.
Replies (3)
RE: Exact data not getting on the browser - Added by gstrauss about 1 month ago
Please refer to the documentation: mod_fastcgi
You need to configure mod_fastcgi to execute your code. Loading "mod_fastcgi" in server.modules
is only the first step.
RE: Exact data not getting on the browser - Added by syedr1 about 1 month ago
Hi gstrauss
After modifying the lighttpd.conf file, I can able to get the proper data.
1.But I get the error "2023-10-21 19:36:26: (configfile.c.1316) source: lighttpd.conf line: 46 pos: 15 parser failed somehow near here: /evenodd "
fastcgi.debug = 1 fastcgi.server = ( "/hello" => (( "bin-path" => "/etc/lighttpd/hello_fastcgi.fcgi", "socket" => "/tmp/hello_fastcgi.sock", "check-local" => "disable", "max-procs" => 2, )) "/evenodd" => (( "bin-path" => "/etc/lighttpd/even_odd.fcgi", "socket" => "/tmp/even_odd.sock", "check-local" => "disable", "max-procs" => 2, )) )
2. If I remove /hello , then I get no error and I can work with /evenodd
If I remove /evenodd , then I get no error and I can work with /hello
Is there a way, Where I can mention both /hello and /evenodd and work with both.
Please suggest
RE: Exact data not getting on the browser - Added by gstrauss about 1 month ago
You're missing a comma after ))
. The comma delineates elements in the list.
You are having trouble with basic syntax. Please see Configuration: File Syntax and read the examples in mod_fastcgi more carefully.