【发布时间】:2019-09-08 00:14:44
【问题描述】:
我正在使用@ErikRas 的入门工具包
使用以下代码,我无法验证我的 python 程序。
这是我的蟒蛇:
import requests
URL="http://localhost"
PORT="3030"
Session = requests.Session()
Request = Session.post(URL+':'+PORT+'/login', data={'name':'AuthedUserName'})
# (Password to follow proof of concept obviously)
在我刚刚拥有的 api.js 文件中:
import express from 'express';
import session from 'express-session';
import bodyParser from 'body-parser';
import config from '../src/config';
import * as actions from './actions/index';
import {mapUrl} from 'utils/url.js';
import http from 'http';
const app = express();
const server = new http.Server(app);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(session({
secret: 'react and redux rule!!!!',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 60000 }
}));
app.use((req, res) => {
/* There's heaps here, but all that is relevant is: */
console.log(req.body)
在控制台中我刚刚得到{}
我找到了这篇文章: req.body empty on posts 和 Python Post Request Body appears empty in Node server when sent
但正如你所见,我已经在使用 bodyparser.json 和 bodyparser.urlencoded.extended = true
【问题讨论】:
-
您是否从 Python 端获得 200?在帖子行后输入
Request.raise_for_status()。 -
我得到了 404,但那是因为 node 得到了 req.body.user == 'undefined' ,所以验证是平淡的。但是现在我有了 headers={},我得到了 200
标签: python node.js rest express