【问题标题】:Print out the whole raw http request打印出整个原始 http 请求
【发布时间】:2012-03-28 21:24:52
【问题描述】:

如何在 python 框架瓶中获取整个原始 http 请求?

我需要这样的东西:

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

我需要这个来签署我的 http api 请求

【问题讨论】:

    标签: python http request hmac bottle


    【解决方案1】:

    据我从the docs 得知,您无法获取原始格式的数据。

    您可以使用bottle.request.data 和bottle.request.headers 重建它。这对于您的目的可能已经足够了。

    【讨论】:

    • bottle.request.method 和 bottle.request.query 是我的解决方案,谢谢!
    【解决方案2】:

    如果您只想打印请求,您可以执行以下操作:

    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)))
    

    【讨论】:

      猜你喜欢
      • 2014-01-06
      • 2014-10-17
      • 2014-10-07
      • 2021-01-20
      • 2021-12-23
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      相关资源
      最近更新 更多