How to set a request body

Mirko Dziadzka mirko.dziadzka at gmail.com
Tue Aug 31 14:01:23 MSD 2010


Hi

I'm still trying to create a POST sub-request. I'm stuck in creating the
correct body of the request. Here is my current (non working) code:

// submit data in a POST request
res = ngx_http_subrequest(r, uri, NULL , &sr, psr, flags);

sr->method = NGX_HTTP_POST;
sr->method_name.data = (u_char *)"POST ";
sr->method_name.len = 4;

// set request body
sr->request_body = ngx_pcalloc(r->pool,sizeof(ngx_http_request_body_t));
sr->request_body->buf = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));

// args is an ngx_str_t with the body
sr->request_body->buf->start = args->data;
sr->request_body->buf->end = args->data + args->len;
sr->request_body->buf->pos = sr->request_body->buf->start;
sr->request_body->buf->last = sr->request_body->buf->end;
sr->request_body_in_single_buf = 1;

// set header, content-type and content-length
...

The request is send to a local uri which is then forwarded via
proxy_pass to another server.

On the network, I see only the header:

POST /decide.cgi HTTP/1.0
Host: 127.0.0.1:8081
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 1217

Can someone please point me to working example code or tell me what I'm
missing here?



More information about the nginx-devel mailing list