I have a classic ASP application which is to send data to a Flask application. The Flask app is on the same server as the classic ASP app and is using the default 127.0.0.1:5000 address. The problem I'm having is the Flask app isn't detecting the POST data.
ASP/vbscript code:
Function sendPostToFlask(sInput)
Dim httpReq, sURL, bAsyncRequest, sPostValue
Set httpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
sURL = "http://127.0.0.1:5000/MyService"
bAsyncRequest = False
sPostValue = "param=" & sInput
On Error Resume Next
Call httpReq.Open("POST", sURL, bAsyncRequest)
Call httpReq.Send(sPostValue)
If (err.number = 0) Then
sendPostToFlask = httpReq.ResponseText
Else
sendPostToFlask = err.Description
End If
On Error GoTo 0
Set httpReq = Nothing
End Function
Flask/python code:
from flask import Flask
from flask import request
import sys
app = Flask(__name__)
@app.route('/MyService', methods=['POST'])
def MyService():
if request.method == 'POST':
postedData = request.form.get('param', 'No posted param data')
return postedData
I know the apps are communicating because I see the Flask console outputting a 200 response with each request, and the classic ASP app is printing the return value from the Flask app but not the one I want; I'm getting the fallback value from request.form.get which suggests the post data is either not being sent or not being received. It just occurred to me as I'm typing this that I should switch to a query string which will probably be more foolproof, but I'm still curious as to why this method doesn't work.