Flask + Wireshark

Flask References:

Wireshark:



Code For w7_03.py

This code has been shortened for focus on the POST aspect of a form.

# w7_03.py

si = """
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
     
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title>Simple Post Example</title>
   </head>
      <body>
         <h1>Login type POST:</h1>
         <ul>
         <li>form: action=login method=post
         <li>label: User Name:
         <li>input: type=text name=un
         <li>label: Password:
         <li>input: type=password name=pwd
         <li>input: type="submit" class=submit value="log in"
         </ul>
         <form action=login method=post>
            <label>User Name:</label>
            <input type=text name=un>
            <br>
            <label>Password:</label>
            <input type=password name=pwd>
            <br>
            <input type="submit" class=submit value="log in">
         </form>

      </body>
</html>
"""
def s01 (st):
   return  """
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
   <html>
      <head>
        
         <meta http-equiv="content-type" content="text/html; charset=UTF-8">
         <title>""" + st + """</title></head><body>"""
        
s99 = """</body></html>"""


from flask import Flask

app = Flask(__name__)

@app.route("/index.html", methods=['GET', 'POST'])
@app.route('/')

def helloIndex():
   return si

from flask import request

# do both get & post to get POST values
# default is just get values
@app.route('/login', methods=['GET', 'POST'])

# http://10.0.0.66:8080/a/other
def logfunc():
   v = "none"
   w1 = "nonew"
   if request.method == 'POST':
      v = "posting"
      print ("Posting")
      w1 = request.form
   if request.method == 'GET':
      v = "getting"
      print ("Getting")
      w1 = request.args
   print (v + str(w1))
   u   = str(w1.get("un"))
   p   = str(w1.get("pwd"))
   s2  = str(s01 ("w7_03.py, version 01"))
   s2 += "Get values >" + v + "< <P>"
   s2 += "un >" + u + "< <P>"
   s2 += "pwd >" + p + "< <P>"
   s2 += """before the form<p>
         <form action="index.html" method=post>
         This is a form - activating the return button.<br>
         <input type="submit" value="return">
         </form>

         <P>after the form"""
   s2 += s99
   return s2

# standard run host server command:  
# app.run(host='0.0.0.0', port= 8080)
# More reliable:
if __name__ == "__main__":
    app.run(host='0.0.0.0', port= 8080)


Wireshark recording

Get the wireshark captured conversation file:


Updated: Dec 11, 2019