Mar 19, 2019 04:01 PM
(This post was last modified: Mar 20, 2019 10:52 AM by Vassilios.)
![[Image: 0KxgOTV.png]](https://i.ipixls.net/0KxgOTV.png)
Sociopaths Tutorials - Starting with Requests | By Nachzehrer
![[Image: Mv5GOED.png]](https://i.ipixls.net/Mv5GOED.png)
What is the Requests library?
Requests is an Apache2 HTTP library, written for python. Requests allow you to send HTTP/1.1 requests to websites and you can also add headers, form data and parameters. It also allows you to access the contents of the website in a quick and friendly way.
How do I install Requests?
If you have pip installed then simply go to your command prompt and type:
Code
pip install requestsDifferent Types of Requests:
GET: Usually when you make a GET request, the website will return a response to you with the content of the website, unless it has anti-bot protection.
POST: POST requests are made in order to send data on the server, we can log into websites using POST requests and much more depending on the website.
What are headers?
Headers are used between you to pass additional information with each-other such as what kind of browser are you using, what kind of language do you want your content presented in, where did you come from and much more!
Code
print(r.headers)This piece of code should show you what kind of headers your request used, if you want to access a specific one you can do:
Code
print(r.headers['name'])Making GET Requests:
Code
r = requests.get('website_url')requests: The name of the library, we need to use it before any operations that uses its functions.
GET: The operation that we are currently doing, it uses a tuple and it tries to retrieve the contents of the string inside it.
Making POST Requests:
Code
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.post("website", data=payload)
print(r.status_code)requests: The name of the library, we need to use it before any operations that uses its functions.
POST: Here we are doing a POST request so we use post instead of GET.
Now you might see something weird which wasn't seen before. The payload and the data=.
Payload is what we want to send to the server, for example if we tried to log into FaceBook our browser would send the following POST request which we can see from Inspect Element > Network:
![[Image: k6CaCbS.png]](https://i.imgur.com/k6CaCbS.png)
Our payload is the "Request Body". We could technically just switch everything and make something such as:
Code
{'jazoest':'2711', 'lsd':'AVq7w8rg' ... }Then send that to the URL up top together with the headers and we should be able to log in as long as there is no serious bot detection. To send the data we just save our dictionary to a variable such as payload and then data=payload in the post request!
This is all you need to start with Requests! Experiment by yourself and make anything you wish, when you get comfortable you could read on other requests such as PUT.
![[Image: VGjo5UA.gif]](https://i.imgur.com/VGjo5UA.gif)



![[Image: 0DvFxnA.gif]](https://i.imgur.com/0DvFxnA.gif)