Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django creating/making POST request with headers

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 :)

like image 448
iskorum Avatar asked Jun 20 '13 06:06

iskorum


1 Answers

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

like image 146
iskorum Avatar answered Sep 23 '22 01:09

iskorum