这是客户:
data = b'48958695427097097402529251103137444756'
r = requests.post("http://127.0.0.1:5000", data=data)
这是服务器:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from flask import Flask, Response, request
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
def get_data():
print('Recieved from client: {}'.format(request.data))
return Response('We recieved something…')
if __name__ == ‘__main__’:
app.run(debug=True)
客户端发送到服务器字节字符串,但服务器仅接收:b'' 为什么呢?
如何让服务器接收整个字节串? 谢谢。
答案 0 :(得分:-1)
您的<ul class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<li class="panel panel-default">
<div class="panel-heading" role="tab" id="collapse-heading-1">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-category-1" aria-expanded="false" aria-controls="collapse-category-1">
My title 1
</a>
</div>
<div class="panel-collapse collapse" id="collapse-category-1" role="tabpanel" aria-labelledby="collapse-heading-1">
<div class="panel-body">
My body 1
</div>
</div>
</li>
<li class="panel panel-default">
<div class="panel-heading" role="tab" id="collapse-heading-2">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-category-2" aria-expanded="false" aria-controls="collapse-category-2">
My title 2
</a>
</div>
<div class="panel-collapse collapse" id="collapse-category-2" role="tabpanel" aria-labelledby="collapse-heading-2">
<div class="panel-body">
My body 2
</div>
</div>
</li>
<li class="panel panel-default">
<div class="panel-heading" role="tab" id="collapse-heading-3">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-category-3" aria-expanded="false" aria-controls="collapse-category-3">
My title 3
</a>
</div>
<div class="panel-collapse collapse" id="collapse-category-3" role="tabpanel" aria-labelledby="collapse-heading-3">
<div class="panel-body">
My body 3
</div>
</div>
</li>
</ul>
不包含任何@app.route
,因此您需要添加
method
要了解@app.route('/',methods=['POST'])
的工作原理,请参阅this
您编辑的代码
@app.route
答案 1 :(得分:-1)
您错过了该行的结尾:
@app.route('/', methods=['POST'])
在这个小修复之后,您的代码应该可以正常工作。