How To Check The Progress Of The Post Request?
I am using python requests package to send a post request to the server. It will invoke a long-time running function in the server side. The server side looks like this: from flask
Solution 1:
I know of 3 options: Ajax polling, Websockets server or 3rd party API. For the latter I'd use rejax.io free plan.
after registering your app and pasting required code, invoking a messsage to client looks like this:
import urllib.request
import json
key = 'KEYzoVONRA4CdMvDzBZXytPyebwMf3sLrLh'
secret = 'SECRETLJAQpPaB6p31q5UOzOBtsmmnbLqFY6z4'
url = "https://rejax.io:3001/api/server"
body = {
'app_key' : key,
'app_secret' : secret,
'channel' : 'my-channel-name',
'text' : 'hello from server'
}
req = urllib.request.Request(url)
req.add_header('Content-Type', 'application/json; charset=utf-8')
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('utf-8') # needs to be bytes
req.add_header('Content-Length', len(jsondataasbytes))
response = urllib.request.urlopen(req, jsondataasbytes)
print (response.status)
receiving the message on client will look like this then
Rejax.listen('my-channel-name', function(text) {
// received text from serverconsole.log(text)
$("#my-progress-bar").css("width", text + "%")
})
link: https://rejax.io disclosure: I wrote it
Post a Comment for "How To Check The Progress Of The Post Request?"