簡體   English   中英

Python:如何獲取HTTP POST / GET請求標頭

[英]Python : How can I get HTTP POST/GET request header

我真的不知道如何提出我的問題,但是我想做的事情是這樣的:

我想打印或獲取所有http事務,例如當我在Chrome或FF中按F12並進入網絡時,可以看到它們。

我試圖用urllib2和請求來做,但我沒有得到我想要的..

requests模塊非常強大,具有訪問響應和請求標頭的方法

In [16]: import requests

In [17]: r = requests.get("http://www.stackoverflow.com")

In [18]: r.headers
Out[18]: CaseInsensitiveDict({'content-length': '36531', 'content-encoding': 'gzip', 'set-cookie': 'prov=62ff4d3c-2d5f-413c-92f6-ad7d116088a9; domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly', 'expires': 'Mon, 29 Sep 2014 16:29:48 GMT', 'vary': '*', 'last-modified': 'Mon, 29 Sep 2014 16:28:48 GMT', 'cache-control': 'public, no-cache="Set-Cookie", max-age=16', 'date': 'Mon, 29 Sep 2014 16:29:32 GMT', 'x-frame-options': 'SAMEORIGIN', 'content-type': 'text/html; charset=utf-8'})

In [19]: r.request.headers
Out[19]: CaseInsensitiveDict({'Accept-Encoding': 'gzip, deflate, compress', 'Accept': '*/*', 'User-Agent': 'python-requests/2.2.1 CPython/2.7.5 Darwin/13.3.0'})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM