开发者

Pass through server / proxy

I'm looking for advice on how this can be done. I want to have a server sit in between the client and the actual server. For example:

Client -> Proxy开发者_Python百科 Type Server -> Web Server.

So in return the web server would pass results to the proxy server which in return give the results back to the client. For example:

Client <- Proxy Type Server <- Web Server

Here is a diagram if it makes life easier:

Pass through server / proxy

If it was just simple GET requests not a problem but I'm not sure how it would work if the client was posting data. I hope someone can advise me on this. Thank you if you can!


I'm not sure what your question is... If you set up a proxy server between your client and the application server, then it will be just that: a proxy server. So it will proxy requests to the application server, just as you've shown in your diagram. If a client POSTs data to the proxy, the proxy server will POST that same data to the application server and return the response to the client...

Are you asking how to set up something like this?

EDIT: I'm going to take a wild guess here...

If it was just simple GET requests not a problem but I'm not sure how it would work if the client was posting data

Do you mean that the client is POSTing to a PHP or Ruby script on the "Proxy Server", and not an actual proxy server like Squid or Apache's mod_proxy? If so, are you asking how, using PHP, to send that POST data to the application server? If that's your question, here's the answer:

<?php

$application_server = '1.2.3.4'; // replace with IP or hostname of application server
$uri = $_SERVER['REQUEST_URI']; // you may need to change this, not sure from your question.

$curl = curl_init("http://{$application_server}{$uri}");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$_POST);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$data = curl_exec($curl);

// do something with $data, transform it however you want...

echo $data;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜