使用Python发送请求(使用Burp拦截)

时间:2017-04-08 19:59:53

标签: python python-3.x http-post burp

我无法理解请求。 让我们说我有这个要求:

POST /user/follow HTTP/1.1
Host: www.website.com
User-Agent: some user agent
Accept: application/json, text/plain, */*
Accept-Language: pl,en-US;q=0.7,en;q=0.3
Referer: https://www.website.com/users/12345/profile
Content-Type: application/json;charset=utf-8
X-CSRF-TOKEN: Ab1/2cde3fGH
Content-Length: 27
Cookie: some-cookie=;
DNT: 1
Connection: close

{"targetUser":"12345"}

我应该如何使用此信息使用python发送有效请求? 我发现的并不是真的有用。我需要有人向我展示我给你的数据的一个例子。

2 个答案:

答案 0 :(得分:3)

我会做这样的事情。

import requests
headers = {
    "User-Agent": "some user agent",
    "Content-Length": 27
    # you get the point
     }
data = {
    "targetUser" : "12345"
    }
url = "www.website.com/user/follow"
r = requests.post(url, headers=headers,data=data)

是的,您可以使用Cookie登录.Cookie是标题的一部分。

答案 1 :(得分:2)

我不会写诗,我只是给你一些exapmle代码:

import requests

headers = {
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language": "en-US,en;q=0.5",
    "Referer": "SOMETHING",
    "Cookie": "SOMETHING",
    "Connection": "close",
    "Content-Type": "application/x-www-form-urlencoded"
}
data = "SOME DATA"
url = "https://example.com/something"

request = requests.post(url, headers=headers, data=data)

在标题中你设置了所需的标题等我认为你得到了它;)