[Answer]-Server Code HTTp POST to remote server; Javascript API call


  1. use the $ajax() function from jquery
  2. use urllib and urllib2 to access external resources from python. Call these libraries from within your view function

Here’s an example for the $ajax function:

    type: "GET",
    url: '/htmlApi/sendSms/',
    data: {
    success: function(data){

here’s an example of a view function that posts data to the remote server:

def verify1(request):
    u = request.session['user']
    u.phone_number = request.GET['phone']

    apiUrl = "http://www.XXXXXXXXX.net/api/send.aspx?username=XXXXXXX&password=XXXXXX&language=1&sender=XXXXXX&mobile=" + request.GET['phone'] + "&message=" + 'ghis' + " is your verification code."
    x = urllib2.urlopen(apiUrl).read()

    return HttpResponse(x)

(This is an automated sms sending api call)


Leave a comment