How to obtain POST application/x-www-form-urlencoded data in separate and cross-domain Flask projects

Flask framework, items are separated before and after . Cannot get data for fetch, backend post;
specific symptoms:

1. getpost;
2. request.form
3. segmentfault;
4. 
        POST
        Formdata
            username: "aaa"
            password: "11221212" 
            
               

backend code

@app.route("/blog/login", methods=["post"])
def login():
        try:
                print(334,request.method, request.form.get("username"))
        except:
                print(11111)
        return "123"

error message

Traceback (most recent call last):
  File "/Users/zhongwangsheng/Developer/PyProject/family/venv/lib/python2.7/site-packages/werkzeug/serving.py", line 270, in run_wsgi
    execute(self.server.app)
  File "/Users/zhongwangsheng/Developer/PyProject/family/venv/lib/python2.7/site-packages/werkzeug/serving.py", line 261, in execute
    write(data)
  File "/Users/zhongwangsheng/Developer/PyProject/family/venv/lib/python2.7/site-packages/werkzeug/serving.py", line 236, in write
    self.send_header("Server", self.version_string())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 401, in send_header
    self.wfile.write("%s: %s\r\n" % (keyword, value))
IOError: [Errno 32] Broken pipe

the following is the modified login code, the same error "request was suspended, no response, about 1 minute later failed error"

@app.route("/blog/login", methods=["post"])
def login():
        try:
                print(111, request.data)
                print(222, request.form)
        except:
                print(333)
        return 1234

the following is the request information sent with fetch

Request URL:http://localhost:8084/blog/login
Referrer Policy:no-referrer-when-downgrade
Provisional headers are shown
Authorization:
Content-Type:application/x-www-form-urlencoded
Origin:http://localhost:8084
Referer:http://localhost:8084/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36 OPR/51.0.2830.55 (Edition Baidu)

Form Data
    password:123456
    username:zws
Mar.01,2021

Test is normal

>>> requests.post('http://127.0.0.1:5000/blog/login', data={'username':'hello'})
<Response [200]>
 * Running on http://127.0.0.1:5000/
(334, 'POST', u'hello')

if other places are normal, you probably didn't write this

.
from flask import request

should not be a cross-domain problem, if cross-domain, will not be able to reach your logical code.
the current information can't tell why, but you can try to replace request.form with request.data try


suggest step-by-step troubleshooting
Don't write anything in the login method first, return a value directly, and verify what you said, "request.form will be suspended as soon as the back-end code appears"

.
Menu