I want to make a POST request programmatically with a custom headers. How can I do that?
Actually i am trying to do this; use google shortener api. Maybe i misunderstood :/
Thanks you in advance :)
The answer working great. But found another solution;
import requests
import json
url = 'https://www.googleapis.com/urlshortener/v1/url'
data = {'longUrl': 'http://www.google.com/'}
headers = {'Content-Type': 'application/json'}
r = requests.post(url, data=json.dumps(data), headers=headers)
then
answer = json.loads(r.text)
or
answer = r.json()
Here is requests
package; code and doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With