make a http request with a custom body as text in python

You can use the requests library in Python to make HTTP requests. Here's an example to make an HTTP POST request with a custom text body:

main.py
import requests

url = "http://example.com/api"
body_text = "your custom text body"

response = requests.post(url, data=body_text)

print(response.text)
153 chars
9 lines

In the example code above, we first import the requests library. Then we define the URL we want to make the request to and the custom text body we want to send. We then make an HTTP POST request using the requests.post() method, passing in the URL and the text body as the data parameter. Finally, we print the response body returned by the server.

related categories

gistlibby LogSnag