简体   繁体   中英

How to do a Request with ColdFusion to Django, GET then POST

My co-worker has another application using ColdFusion that he queries phone numbers, but I need to retrieve the query and put into my Django application. GET variable from ColdFusion to Django form, then save is what I would like. He also put a response Variable for me to retrieve, but not sure how. Is that possible?

What it does right now is once you click submit, all the results of the phone number opens in a popup. But instead of having to copy and paste all the info, would be nice to have it load into the Django form.

Below is an example what I have so far:

<form name="input" action="http://friendurlapi/" method="get">
    Password: <input type="text" name="pw"><br>
    Phone Number: <input type="text" name="PhoneNumber"><br>

    <select name="MTS">
        <option value="MVI">Incoming Voice</option>
        <option value="MVO">Outgoing Voice</option>
        <option value="SMO">Outgoing SMS</option>
    </select>

    From Date: <input type="text" name="FromDATE"><br>
    To Date: <input type="text" name="ToDATE"><br>

    <input type="submit" value="Submit">
</form>

Result is something like this that I need to be inputted into a text field automatically.

1/01/2014,12:00:00,XXXXXXXXX,XXXXXXXXX,XXXX,XX,XXXXXXXXXXXXXX

All help is appreciated.

Rather than submitting the form from your browser (via a <form> element), one option is to create a normal Django form and query your friend's API on the backend using something like this:

 apiUrl = 'http://friendurlapi/?pw=foo&PhoneNumber=bar...'

 # import requests
 response = requests.get(apiUrl)

 # import urllib2
 fd = urllib2.urlopen(apiUrl)
 response = fd.read()
 fd.close()

In this case, your friend's API would actually see the request coming from your web server, not the user's. (You should also consider whether it's secure to send the password as a GET parameter; if it's a user password rather than a revocable API key, this is probably a bad idea.)

An alternative would be to query the API using JavaScript and insert the response into the DOM once it is returned. Using jQuery:

$('form[name="input"]').submit(function() {
    $.get('http://friendurlapi/', {
        // get the options out of the form
        pw: $('input[name="pw"]').val(), 
        PhoneNumber: $('input[name="PhoneNumber"]').val(),
        // ...
    }, function(data) {
        // once the response from the form is received,
        // put it into your text box
        $('#textbox').text(data);
    });
})

Neither of these options are particularly elegant, but the first is probably better since it's more likely to hide the API from the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM