访问 bottle post 参数
Access bottle post parameters
我正在 post 使用 axios 库 post 将两个 post 参数与节点 js 绑定到瓶服务中
var axios = require('axios')
axios.post('http://localhost:8080/filter-tags', {
xml: 'Fred',
tags: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
我的瓶装服务是
from bottle import route, run, request
from pprint import pprint
@route('/filter-tags', method='POST')
def filterTags():
xml1 = request.POST.xml
xml2 = request.forms.get('xml')
print(pprint(vars(request.POST)))
print('-->' + xml1 +'<----')
print(xml2)
return 'trololo'
run(host='localhost', port=8080, debug=True)
我的输出是
{'dict': {'{"xml":"Fred","tags":"Flintstone"}': ['']}}
None // don't know why this value appears here
--><---- // xml1
None // xml2
Here 是 link 装瓶文档,但我看不出我的错误
知道如何访问参数吗?谢谢。
By default, axios serializes JavaScript objects to JSON
。我相信您正在使用 Node.js 库。请考虑使用<a href="https://nodejs.org/api/querystring.html" rel="nofollow noreferrer">querystring</a>
发送application/x-www-form-urlencoded
格式
var querystring = require('querystring');
axios.post('http://localhost:8080/filter-tags', querystring.stringify({
xml: 'Fred',
tags: 'Flintstone'
}));
这样做你会得到{'dict': {'xml': ['Fred'], 'tags': ['Flintstone']}}
,这很容易得到数据。在这种情况下只是 request.POST.xml
我正在 post 使用 axios 库 post 将两个 post 参数与节点 js 绑定到瓶服务中
var axios = require('axios')
axios.post('http://localhost:8080/filter-tags', {
xml: 'Fred',
tags: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
我的瓶装服务是
from bottle import route, run, request
from pprint import pprint
@route('/filter-tags', method='POST')
def filterTags():
xml1 = request.POST.xml
xml2 = request.forms.get('xml')
print(pprint(vars(request.POST)))
print('-->' + xml1 +'<----')
print(xml2)
return 'trololo'
run(host='localhost', port=8080, debug=True)
我的输出是
{'dict': {'{"xml":"Fred","tags":"Flintstone"}': ['']}}
None // don't know why this value appears here
--><---- // xml1
None // xml2
Here 是 link 装瓶文档,但我看不出我的错误
知道如何访问参数吗?谢谢。
By default, axios serializes JavaScript objects to JSON
。我相信您正在使用 Node.js 库。请考虑使用<a href="https://nodejs.org/api/querystring.html" rel="nofollow noreferrer">querystring</a>
发送application/x-www-form-urlencoded
格式
var querystring = require('querystring');
axios.post('http://localhost:8080/filter-tags', querystring.stringify({
xml: 'Fred',
tags: 'Flintstone'
}));
这样做你会得到{'dict': {'xml': ['Fred'], 'tags': ['Flintstone']}}
,这很容易得到数据。在这种情况下只是 request.POST.xml