19
我正在努力解決這個奇怪的問題,我似乎無法解決。我使用同構提取來將數據發佈到服務器。我將該身體作爲JSON字符串發送。但在服務器上,我無法讀取正文,它只是一個空的對象。isomorphic fetch post無法讀取服務器上的身體
堆棧是:node,react。
這裏是客戶端代碼:
handleSubmit = (event) => {
const { dispatch } = this.props;
fetch('/api/me', {
method: 'POST',
header: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'xxx'
})
})
.then(response => response.json())
.then(json => dispatch(login(json)))
.catch(err => console.log(err))
}
服務器代碼:
var jsonParser = bodyParser.json()
app.post('/api/me', jsonParser, (req, res) => {
console.log('req', req.body);
})
我試着用搜索引擎的問題。但我發現的少數解決方案並沒有達到目的。
非常感謝所有幫助。
BR
馬丁
// // UPDATE
想通了,這是一個愚蠢的',我已經忘了。 「頭」應該是「頭」