Richard Walker Richard Walker - 1 year ago 63
HTTP Question

Is it possible to pass a space character to a cgi?

I have a compiled c binary (setch) which takes the parameters

so I am trying to execute the command eg
setch OFF
from javascript/jquery thus:

$.get("cgi-bin/setch.cgi","OFF"); -or
$.get("cgi-bin/setch OFF");

As it's a get then the space is encoded into %20, of course. However the server then tries to execute the command
and returns:

404 Not Found

Without the parameter the program executes and returns my message:

no parameters

ie all paths, permissions etc are OK

Am I trying to do the impossible here? Or am I missing something in the server (lighttpd) config?

Answer Source

You want to pass a parameter to a CGI. The way to do that is not to separate them with a space, instead you want to put the parameter behind a "?" character. The HTTP server will then store everything that follows behind the question mark in the QUERY_STRING environment variable that your CGI can then read.



In your C program use getenv("QUERY_STRING") to access the passed parameter.

Check for a list of all environment variables that the HTTP server set for CGI programs. Be sure to treat the values as untrusted data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download