Send requests using Python (intercepted using Burp)

I'm having trouble understanding queries. Say I have this query:

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"}

How should I use this information to send a valid request using python? What I found is not very useful. I need someone to show me an example with the data that I gave you.

+4
source share
2 answers

I would do something like this.

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)

Yes, you must use cookies to log in. Cookies are part of the headers.

+3
source

I will not write poetry, but simply give you the exapmle code:

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)

.., , ;)

+2

Source: https://habr.com/ru/post/1674387/


All Articles