简体   繁体   中英

Print out the whole raw http request

how do I get the whole raw http request in the python framework bottle?

I need something like this:

GET\n
myurl.com\n
/\n
attribute=value
&att2=value2

I need this to sign my http api requests

As far as I can tell from the docs you can't get the data in raw format.

What you can do is reconstruct it using bottle.request.data and bottle.request.headers . That may be enough for your purposes.

If you just want to print the request you can do the following:

headers_string = ['{}: {}'.format(h, request.headers.get(h)) for h in request.headers.keys()] 
print('URL={}, method={}\nheaders:\n{}'.format(request.url, request.method, '\n'.join(headers_string)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM