第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

req.body在帖子上空了

req.body在帖子上空了

侃侃爾雅 2019-08-16 14:47:10
req.body在帖子上空了我的所有項(xiàng)目都突然發(fā)生了這種情況。每當(dāng)我使用express和body-parser在nodejs中發(fā)表帖子時(shí)req.body都是一個(gè)空對(duì)象。var express    = require('express')var bodyParser = require('body-parser')var app = express()// parse application/x-www-form-urlencodedapp.use(bodyParser.urlencoded())// parse application/jsonapp.use(bodyParser.json())app.listen(2000);app.post("/", function (req, res) {   console.log(req.body) // populated!   res.send(200, req.body);});通過(guò)ajax和postman它總是空的。但是通過(guò)卷曲$ curl -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz"}' http://localhost:2000/它按預(yù)期工作。我嘗試手動(dòng)設(shè)置Content-type :  application/json前者,但我總是得到400 bad request這讓我發(fā)瘋了。我認(rèn)為這是在身體解析器中更新的東西,但我降級(jí)了,但沒(méi)有幫助。任何幫助表示感謝,謝謝。
查看完整描述

3 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊

使用Postman,要使用原始JSON數(shù)據(jù)有效負(fù)載測(cè)試HTTP post操作,請(qǐng)選擇該raw選項(xiàng)并設(shè)置以下標(biāo)頭參數(shù):

Content-Type: application/json

另外,請(qǐng)務(wù)必用雙引號(hào)將JSON有效內(nèi)容中用作鍵/值的任何字符串包裝起來(lái)。

body-parser包將解析多行原始JSON有效負(fù)載。

{
    "foo": "bar"}

使用Postman v0.8.4.13擴(kuò)展(body-parserv1.12.2和expressv4.12.3)在Chrome v37和v41中進(jìn)行了測(cè)試,其設(shè)置如下:

var express = require('express');var app = express();var bodyParser = require('body-parser');// configure the app to use bodyParser()app.use(bodyParser.urlencoded({
    extended: true}));app.use(bodyParser.json());// ... Your routes and methods here


查看完整回答
反對(duì) 回復(fù) 2019-08-16
?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊

我犯了一個(gè)非常愚蠢的錯(cuò)誤,忘了name在我的html文件中定義輸入的屬性。

而不是

<input type="password" class="form-control" id="password">

我有這個(gè)。

<input type="password" class="form-control" id="password" name="password">

現(xiàn)在request.body填充如下:{ password: 'hhiiii' }


查看完整回答
反對(duì) 回復(fù) 2019-08-16
  • 3 回答
  • 0 關(guān)注
  • 825 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)