[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modules
Subject:    Re: [apache-modules] how to read POST send URL arguments?
From:       Christian Parpart <cparpart () surakware ! net>
Date:       2003-06-29 5:49:57
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sunday 29 June 2003 4:40 am, Ajit Chourasia wrote:
[....]
> I hope this helps . Let me know if you find a better way.

Hi thou,

well, first I've to say thank you, this code snippet really helped 
me finding out that I was wrong the whole night, because I thought 
that I've to do something with ap_hook_post_read_request() 
because it contains post, read, and request *heh*.

While I do *not* understand everything from your snippet, I found 
a similar way (with your help) as I wanna show you below.

I also did not know that I've to read the request body inside my own 
handler, becuase I first thgouth that I need to register a hook for it ;)

Well, sorry, I'm C++ coder, just in case you don't like it, but you 
can easily exchange new/delete with malloc/free and std::string with 
something similar, see below:

- -------------------------------------------------------------------
typedef std::map<std::string, std::string> TStringMap;
TStringMap FRequestArguments;

bool readPostArguments(request_rec *r) {
    if (ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))
        return false;

    if (!ap_should_client_block(r))
        return false;

    char *postData = new char[r->remaining + 1];
    do {
        char *p = postData;
        int nleft = r->remaining, nread;

        for (; (nread = ap_get_client_block(r, p, nleft)) > 0; p += nread, nleft -= nread);
        *p = 0;
    } while (0);

    for (char *p = postData; *p;) {
        unsigned len = 0;
        for (char *q = p; *q && *q != '='; ++q, ++len);
        std::string name(p, len);
	p += len + 1;

        len = 0;
        for (char *q = p; *q && *q != '&'; ++q, ++len);
        std::string value(p, len);
        *(p += len) ? ++p : 0;

        FRequestArguments[name] = value;
    }
    delete[] postData;

    return true;
}
- -------------------------------------------------------------------
when this method gets called all name:value pairs are
stored in FRequestArguments and can be easily requested with

value = FRequestArguments["name"]; // ;-)

Thanks,
Christian.
- -- 
 07:26:54 up 39 days, 22:41,  0 users,  load average: 0.00, 0.00, 0.00
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+/n4HPpa2GmDVhK0RAgNIAJ9V5iy1yg8tH454oh8EAE+gaYaMzACfbINn
g+2oUJ18yIrh2zDIrpmmVrA=
=aANv
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: apache-modules-unsubscribe@covalent.net
For additional commands, e-mail: apache-modules-help@covalent.net


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic