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

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

錯(cuò)誤:無(wú)法在將標(biāo)頭發(fā)送到客戶端后設(shè)置標(biāo)頭

錯(cuò)誤:無(wú)法在將標(biāo)頭發(fā)送到客戶端后設(shè)置標(biāo)頭

錯(cuò)誤:無(wú)法在將標(biāo)頭發(fā)送到客戶端后設(shè)置標(biāo)頭我是Node.js的新手,我遇到了一些問(wèn)題。我使用的是Node.js 4.10和Express 2.4.3。當(dāng)我嘗試訪問(wèn)http://127.0.0.1:8888/auth/facebook時(shí),我將被重定向到http://127.0.0.1:8888/auth/facebook_callback。然后我收到以下錯(cuò)誤:Error: Can't render headers after they are sent to the client.     at ServerResponse.<anonymous> (http.js:573:11)     at ServerResponse._renderHeaders (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:64:25)     at ServerResponse.writeHead (http.js:813:20)     at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/auth.strategies/facebook.js:28:15     at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/index.js:113:13     at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/strategyExecutor.js:45:39)var fbId= "XXX";var fbSecret= "XXXXXX";var fbCallbackAddress= "http://127.0.0.1:8888/auth/facebook_callback"var cookieSecret = "node";// enter a random hash for securityvar express= require('express');var auth = require('connect-auth')var app = express.createServer(); app.configure(function(){     app.use(express.bodyParser());     app.use(express.methodOverride());     app.use(express.cookieParser());     app.use(express.session({secret: cookieSecret}));     app.use(auth([         auth.Facebook({             appId : fbId,             appSecret: fbSecret,             callback: fbCallbackAddress,             scope: 'offline_access,email,user_about_me,user_activities,manage_pages,publish_stream',             failedUri: '/noauth'         })     ]));     app.use(app.router);});app.get('/auth/facebook', function(req, res) {   req.authenticate("facebook", function(error, authenticated) {     if (authenticated) {       res.redirect("/great");       console.log("ok cool.");       console.log(res['req']['session']);     }我可以知道我的代碼有什么問(wèn)題嗎?
查看完整描述

3 回答

?
慕雪6442864

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

resExpress中的對(duì)象是Node.js的http.ServerResponse子類(讀取http.js源代碼)。您可以隨時(shí)撥打電話res.setHeader(name, value),直到您打電話為止res.writeHead(statusCode)。之后writeHead,標(biāo)題被烘焙,您只能調(diào)用res.write(data),最后res.end(data)。

錯(cuò)誤“錯(cuò)誤:發(fā)送后無(wú)法設(shè)置標(biāo)頭”。表示您已處于Body或Finished狀態(tài),但某些函數(shù)嘗試設(shè)置標(biāo)題或statusCode。當(dāng)您看到此錯(cuò)誤時(shí),嘗試查找在已經(jīng)寫入某些正文后嘗試發(fā)送標(biāo)頭的任何內(nèi)容。例如,查找意外調(diào)用兩次的回調(diào),或發(fā)送正文后發(fā)生的任何錯(cuò)誤。

在你的情況下,你打電話res.redirect(),導(dǎo)致響應(yīng)成為完成。然后你的代碼拋出一個(gè)錯(cuò)誤(res.reqnull)。并且由于錯(cuò)誤發(fā)生在您的實(shí)際內(nèi)function(req, res, next)(不在回調(diào)中),Connect能夠捕獲它,然后嘗試發(fā)送500錯(cuò)誤頁(yè)面。但由于標(biāo)題已經(jīng)發(fā)送,Node.js setHeader拋出了你看到的錯(cuò)誤。

Node.js / Express響應(yīng)方法的完整列表以及何時(shí)必須調(diào)用它們:

回復(fù)必須在Head并保持在Head

  1. res.writeContinue()

  2. res.statusCode = 404

  3. res.setHeader(name, value)

  4. res.getHeader(name)

  5. res.removeHeader(name)

  6. res.header(key[, val]) (僅限快遞)

  7. res.charset = 'utf-8' (僅限Express;僅影響特定于Express的方法)

  8. res.contentType(type) (僅限快遞)

響應(yīng)必須在Head并成為Body

  1. res.writeHead(statusCode, [reasonPhrase], [headers])

響應(yīng)可以在頭部/身體中,并保留在身體中

  1. res.write(chunk, encoding='utf8')

響應(yīng)可以在頭部/身體中完成并且完成

  1. res.end([data], [encoding])

響應(yīng)可以在頭部/身體中,并保持其當(dāng)前狀態(tài):

  1. res.addTrailers(headers)

響應(yīng)必須在Head并且已完成

  1. return next([err]) (僅限連接/快速)

  2. 中間件中的任何異常function(req, res, next)(僅限Connect / Express)

  3. res.send(body|status[, headers|status[, status]]) (僅限快遞)

  4. res.attachment(filename) (僅限快遞)

  5. res.sendfile(path[, options[, callback]]) (僅限快遞)

  6. res.json(obj[, headers|status[, status]]) (僅限快遞)

  7. res.redirect(url[, status]) (僅限快遞)

  8. res.cookie(name, val[, options]) (僅限快遞)

  9. res.clearCookie(name[, options]) (僅限快遞)

  10. res.render(view[, options[, fn]]) (僅限快遞)

  11. res.partial(view[, options]) (僅限快遞)


查看完整回答
反對(duì) 回復(fù) 2019-05-27
?
暮色呼如

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

我有同樣的問(wèn)題并且意識(shí)到這是因?yàn)槲以?code>res.redirect沒(méi)有return聲明的情況下進(jìn)行調(diào)用,所以next之后也立即調(diào)用了該函數(shù):

auth.annonymousOnly = function(req, res, next) {
    if (req.user) res.redirect('/');
    next();};

應(yīng)該是:

auth.annonymousOnly = function(req, res, next) {
    if (req.user) return res.redirect('/');
    next();};


查看完整回答
反對(duì) 回復(fù) 2019-05-27
  • 3 回答
  • 0 關(guān)注
  • 1682 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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