On Mon, Mar 16, 2009 at 19:04, Saju Pillai <saju.pil...@gmail.com> wrote:
> Sorin Manolache wrote:
>>
>> 2009/3/16 Arturo 'Buanzo' Busleiman <bua...@buanzo.com.ar>:
>>>
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA512
>>>
>>> Hi! From within my module, I'd like to make an HTTP request from another
>>> HTTP server, get something
>>> from it, and use the returned information. What's the best way to do
>>> this?
>>
>> You can use sub-requests. See ap_sub_req_method_uri and ap_run_sub_req.
>
> I think OP wants to know how to make a HTTP request to *another* HTTP
> server.

He can make a ap_sub_req_method_uri to an arbitrary path and then use
a rewrite rule to proxify the request:

RewriteCond %{IS_SUBREQ} true
RewriteRule  /internal_path http://another_http_server/real_path [P]

newreq = ap_sub_req_method_uri("GET", "/internal_path", r, NULL);
// here you set the filter that parses the other's server response
flt = ap_add_output_filter(my_filter, 0, newreq, newreq->connection);
// the filter will store the extracted data in the structure below
struct reponse_data response;
flt->ctx = &response;

int proxy_ret_code = ap_run_sub_req(newreq);
int server_ret_code = newreq->status;
        
// destroy the subrequest
ap_destroy_sub_req(newreq);

if (ap_is_HTTP_ERROR(proxy_ret_code) || ap_is_HTTP_ERROR(server_ret_code)) {
// error handling
}

> I have used a socket speaking a bastardized impl of HTTP - but that was a
> very specialized case.
>
> For more robust HTTP handling from within an apache module, I would use the
> libcurl api. Technically you should be able to use most HTTP client
> libraries that are callable from C.
>
> srp
> --
> http://saju.net.in
>



-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Reply via email to