Reputation: 139
I'm having trouble understanding requests. Let's say I have this request:
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 am I supposed to use this information to send a valid request using python? What I found is not really helpful. I need someone to show me an example with the data I gave you.
Upvotes: 4
Views: 7122
Reputation: 41
This Burp extension may help: Copy As Python-Requests
It can copy selected request(s) as Python-Requests invocations.
In your case, after copying as Python-Requests, you get:
import requests
burp0_url = "http://www.website.com:80/user/follow"
burp0_cookies = {"some-cookie": ""}
burp0_headers = {"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", "DNT": "1", "Connection": "close"}
burp0_json={"targetUser": "12345"}
requests.post(burp0_url, headers=burp0_headers, cookies=burp0_cookies, json=burp0_json)
Upvotes: -2
Reputation: 288
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 would use cookies to log in. Cookies are a part of the headers.
Upvotes: 3
Reputation: 737
I will not write poems i just give you some 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)
In headers you set needed header etc. you got it i think ;)
Upvotes: 2