Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # To make an HTTP request in Python, you can use the requests library. This library provides a convenient and easy-to-use interface for sending HTTP requests in Python.
- # Here is an example of how to send a GET request to retrieve the contents of a webpage:
- import requests
- url = 'https://www.example.com/'
- response = requests.get(url)
- print(response.content)
- # This will print the HTML content of the webpage to the console.
- # You can also send POST requests, set request headers, and handle other HTTP methods using the requests library. Here is an example of how to send a POST request with a JSON payload:
- import requests
- url = 'https://www.example.com/api/create'
- headers = {'Content-Type': 'application/json'}
- data = {'key': 'value'}
- response = requests.post(url, headers=headers, json=data)
- print(response.status_code)
- # For more information about the requests library, you can refer to the documentation: https://requests.readthedocs.io/en/latest/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement