[英]Learning locker statement forwarding
我有在我的計算機上本地運行的學習儲物櫃,我想在外部網站上顯示這些語句,這很容易使用儀表板,因為可以選擇將鏈接放入 iframe,但是當我執行與聲明的部分相同,它說 ip(學習儲物櫃)已阻止訪問,所以我嘗試將語句轉發到 node.js 服務器創建為:
const http = require('http');
const { parse } = require('querystring');
const server = http.createServer((req, res) => {
if (req.method === 'POST')
{
console.log(req);
}
});
server.listen(8090);
但是當我查看 req(傳入消息)並且它顯示為空時,我有一些字段作為標題:
headers:
{ accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
'x-experience-api-version': '1.0.0',
'user-agent': 'axios/0.18.1',
'content-length': '532',
host: 'IP_ADDRESS:8090',
connection: 'close' },
rawHeaders:
[ 'Accept',
'application/json, text/plain, */*',
'Content-Type',
'application/json',
'X-Experience-API-Version',
'1.0.0',
'User-Agent',
'axios/0.18.1',
'Content-Length',
'532',
'Host',
'IP_ADDRESS:8090',
'Connection',
'close' ],
但是沒有正文,也沒有與該聲明相關的內容。
默認情況下,nodejs 服務器不解析 POST 正文。 您可以嘗試將https://www.npmjs.com/package/body-parser中間件與 express.js 框架一起使用
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(function (req, res) {
res.setHeader('Content-Type', 'text/plain')
res.write('you posted:\n')
res.end(JSON.stringify(req.body, null, 2))
})
app.listen(8090, function(error){
if(error) {
throw error
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.