前后分离且跨域的Flask项目 中 POST application/x-www-form-urlencoded 数据的怎么获取

Flask框架,项目是前后分离。请求为fetch,后端post拿不到数据;具体症状:
1.get可以获取,post请求发出后请求被挂起,页面没有响应;
2.只要后端代码出现request.form就会出现被挂起
3.搜索网上和segmentfault的写法,均无效;
4.请求是
POST
Formdata
username:'aaa'
password:'11221212'
后端代码
@app.route('/blog/login',methods=['post'])
deflogin():
try:
print(334,request.method,request.form.get('username'))
except:
print(11111)
return'123'
错误信息
Traceback(mostrecentcalllast):
File"/Users/zhongwangsheng/Developer/PyProject/family/venv/lib/python2.7/site-packages/werkzeug/serving.py",line270,inrun_wsgi
execute(self.server.app)
File"/Users/zhongwangsheng/Developer/PyProject/family/venv/lib/python2.7/site-packages/werkzeug/serving.py",line261,inexecute
write(data)
File"/Users/zhongwangsheng/Developer/PyProject/family/venv/lib/python2.7/site-packages/werkzeug/serving.py",line236,inwrite
self.send_header('Server',self.version_string())
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py",line401,insend_header
self.wfile.write("%s:%s\r\n"%(keyword,value))
IOError:[Errno32]Brokenpipe
以下为修改后的登录代码,还是一样的错误“请求被挂起,没反应,约1分钟后失败error”
@app.route('/blog/login',methods=['post'])
deflogin():
try:
print(111,request.data)
print(222,request.form)
except:
print(333)
return1234
以下是用fetch发送的请求信息
RequestURL:http://localhost:8084/blog/login
ReferrerPolicy:no-referrer-when-downgrade
Provisionalheadersareshown
Authorization:
Content-Type:application/x-www-form-urlencoded
Origin:http://localhost:8084
Referer:http://localhost:8084/
User-Agent:Mozilla/5.0(Macintosh;IntelMacOSX10_13_3)AppleWebKit/537.36(KHTML,likeGecko)Chrome/64.0.3282.186Safari/537.36OPR/51.0.2830.55(EditionBaidu)
FormData
password:123456
username:zws
慕后森
浏览 915回答 2
2回答

GCT1015

应该不会是跨域问题的,假如跨域了,是到不了你的逻辑代码的。现在的信息判断不出为什么,但是你可以尝试把request.form替换成request.data试下
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript