Sending FORM data POST using Python Requests library
I regularly use python requests library at work. Most times, I used JSON as medium for communication between client and server.
Recently, I had a problem where i had to send FORM data to an API instead of JSON.
My backend server is hosted at http://localhost:8080
http://localhost:8080/login is the end point I want to hit with username and password as form data.
So this is how I solved
import requests
url = "http://localhost:8080/login"
form_data = {"username":"johndoe", "password": "user@1234"}
resp = requests.post(url, data=form_data)
while sending JSON data, one would use json=form_data instead in the code snippet above. That’s the difference