javascript - server code HTTP POST to the remote server - Django -
so i'm trying call api ajax. i've made ajax call local url. want local url make url call , return returned data. url restful.
$.ajax({ type: 'post', datatype: 'application/json', accept: 'application/json', async: false, username: 'username', password: 'password', url: '/postdata/', data: { "name": "marcus0.7", "start": 500000, "end": 1361640526000 }, success: function(){alert('done!');}, error:function(error){alert(error)}, });
the api i'm trying call (in python): this want implement server side how do this?
r = requests.post('https//extenal.api' ,headers={'content-type': 'application/json'}, auth=auth, data=json.dumps(data))
in django:
views.py
def postdata(request): return render(request, 'livestream/postdata.html')
urls.py
url(r'^postdata$', 'livestream.views.postdata')
thanks
ajax can cross-domain calls, other domain must allow using cors.
however, if need reflect external api own domain, can set web server reverse proxy relevant endpoints of external api. more performant proxying through django. can use web server add authentication details proxied request.
Comments
Post a Comment