Answer the question
In order to leave comments, you need to log in
How to pass the request to another URL?
Hello. I am using Tornado server. The bottom line is that the front sent a request to a third-party service at a given URl. Now I need to implement the Handler to which this request is sent, and this handler must send the request to the desired url. Those. I need to implement an intermediary so that the front sends requests only to my server, and the server is already on the necessary services. The bottom line is that you need to transfer all headers, cookies and the request body to the given url.
How can I implement this?
Thank you.
Answer the question
In order to leave comments, you need to log in
An example of how this can be done on aiohttp/python3.5:
from aiohttp import web, ClientSession
class ProxyHandler(web.View):
BAD_REQUEST_HEADERS = ['host', 'accept-encoding']
BAD_RESPONSE_HEADERS = ['content-encoding', 'transfer-encoding']
async def get(self):
url = request.GET.get('url')
request_headers = []
# убиваем "вредные" залоговки запроса
for key, value in request.headers.items():
if key.lower() in self.BAD_REQUEST_HEADERS:
continue
response_headers.append(key, value)
with ClientSession() as session:
async with session.get(url, headers=request_headers) as response:
response_headers = []
# убиваем "вредные" залоговки ответа
for item in response.headers:
key, value = item
if key.lower() in self.BAD_RESPONSE_HEADERS:
continue
response_headers.append((key, value))
body = await response.read()
return web.Response(body=body, headers=response_headers, status=response.status)
According to the documentation, you need an AsyncHTTPClient . The required parameters can be set via the Request object passed to the fetch method . Try it.
looks like you need a reverse proxy (for example https://www.nginx.com/resources/admin-guide/revers...
You return an array of associative arrays, which in js turns into an array of objects. And this array does not, of course, have an id property . Try to output to the console obj to the console after parsing and see for yourself.
Well, your request can be replaced by
$.getJSON(
"db.php",
{ func: "GetFullInfo", id: CurId },
success: function( data )
{
// здесь data уже распарсенный json
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question