1

with gwan server, is it possible to get the request string... ie. the arguments.

given http://myserver.com/main.cpp?arg1=one&arg2=two

im looking to obtain a char string arg1=one&arg2=two

according to docs, it should be

REQ_ENTITY,      // char  *ENTITY          // "arg=x&arg=y..."

but doing this gives me an empty string (using args on the above url)

char * req = (char*) get_env(argv, REQ_ENTITY);
xbuf_cat(get_reply(argv), req);;

aha. i should add that get_arg( "arg1" ...) works no problem on that exact same url string (suggesting that its in there somewhere. perhaps the raw query string

a hint or pointer to an example might be all thats needed. also it would be nice to have that work with a mapping/redirect at some point. http://myserver.com/main/arg1=one&arg2=two

regards

Gabe Rainbow
  • 3,658
  • 4
  • 32
  • 42
  • **REQ_ENTITY** is for **PUT** or **POST** rather than for GET. You can use XBUF_READ, QUERY_STRING, etc. (see the http://gwan.ch/source/argv.c and http://gwan.ch/source/served_from.c examples). – Gil Jan 31 '13 at 08:47
  • QUERY_STRING offers the csp name, and no arguments. but perhaps of the get vs post. the loop while (i < argc) method is satisfactory. – Gabe Rainbow Feb 01 '13 at 21:23
  • QUERY_STRING will give you all the parameters if called before PARSING (from a handler). After parsing, you can use get_arg() or main() argv[argc], see the argv.c example. – Gil Feb 03 '13 at 09:19

2 Answers2

0

This nice snippet of code works for my purpose. found in the docs. Just concat them. so love working in c on the server.

int i = 0;
while(i < argc)
{
    xbuf_xcat(get_reply(argv), "argv[%u] '%s'   <br>", i, argv[i]);
    i++;
}

and adapted it to the following:

string concatArgs(void) {
    stringstream ss;
    int i = 0;
    while(i < argc) {
        ss << argv[i++];
    }
    return ss.str();
}
Gabe Rainbow
  • 3,658
  • 4
  • 32
  • 42
0

A quick note about REQ_ENTITY.

Your sample above doesn't have a REQ_ENTITY since you are only doing a GET request. If a request have an Entity Body (Like POST) you can get the Entity Body using REQ_ENTITY but usually you don't need to since you can access it using your sample (stepping through argv) or by using get_arg().

get_arg() sample

Richard Heath
  • 349
  • 3
  • 12