Thread: CGI Help

CGI Help

From
"Jeff"
Date:
Hi,

I have a cgi script that runs fine under command-line

But when execute from a client browser, I get CGI Error
The specified CGI application misbehaved by not returning a complete set of
HTTP headers. The headers it did return are:

It seems like it is not able to connect to the host.

here's what I have in my pg_hba.conf
local        all                                           trust
host         all         127.0.0.1     255.255.255.255     trust
test         all         192.168.38.0    255.255.255.0     trust

executing from client browser
http://www.test.com/cgi-bin/test.cgi

int main()
{
  char *queryString, *contentTypeFromPost, *contentTypeLength;
  int icontentLength, i, j;
  char database[100], *p;
  char contentType[] = "text/html", TheDomainName[100], thisfax[25];
  char today[81];
  ItemList items, *orderlst = NULL, *ip;
  char        state_code[3];                          /* holds state code
entered by user
  char        query_string[256];                      /* holds constructed
SQL query */
  PGconn     *conn;                                   /* holds database
connection */
  PGresult   *res;                                    /* holds query result
*/

  /* setup the html document header */
  printf("Content-Type: %s\n\n", contentType);
  conn = PQconnectdb("dbname=template1");                  /* connect to the
database */

  if (PQstatus(conn) == CONNECTION_BAD)               /* did the database
connection fail?
  {
    printf("Connection to database failed.\n");
    printf("%s", PQerrorMessage(conn));
    return(1);
  }

  strcpy(query_string,                               /* create an SQL query
string */
          "SELECT * FROM cities");

  res = PQexec(conn, query_string);                   /* send the query */

  if (PQresultStatus(res) != PGRES_TUPLES_OK)         /* did the query fail?
*/
  {
    printf("SELECT query failed.\n");
            PQclear(res);
            PQfinish(conn);
            return(1);
  }

  for (i = 0; i < PQntuples(res); i++)                /* loop through all
rows returned */
  {
     printf("%s\n", PQgetvalue(res, i, 0));          /* print the value
returned */
     printf("%s\n", PQgetvalue(res, i, 1));          /* print the value
returned */
     printf("%s\n", PQgetvalue(res, i, 2));          /* print the value
returned */
  }
  PQclear(res);                                       /* free result */

  PQfinish(conn);                                     /* disconnect from the
database */

return(0);

}



Re: CGI Help

From
Tom Lane
Date:
"Jeff" <jklcom@mindspring.com> writes:
> I have a cgi script that runs fine under command-line
> But when execute from a client browser, I get CGI Error
> The specified CGI application misbehaved by not returning a complete set of
> HTTP headers. The headers it did return are:

> It seems like it is not able to connect to the host.

Have you verified that theory by looking in the postmaster log?
What shows up in the log, anyway?

> here's what I have in my pg_hba.conf
> local        all                                           trust
> host         all         127.0.0.1     255.255.255.255     trust
> test         all         192.168.38.0    255.255.255.0     trust

> executing from client browser
> http://www.test.com/cgi-bin/test.cgi

That line beginning "test" is going to be rejected by the postmaster...
should say "host".

BTW, if your CGI is executing under a virtual IP address, the client
address seen by the postmaster may be that virtual IP not the real IP.

            regards, tom lane