简体   繁体   English

得到以下TypeError错误,当我尝试使用Node.js请求模块传递标头信息时

[英]Getting following TypeError error, When I try to pass the header information using nodejs request module

exports.loginUser = function(req, res) {

    console.log(req.body.loginemail);
    console.log(req.body.loginpassword);

    var options = {
        uri: webServiceURL.login,
          method: "POST",
        body: {
            "login": req.body.loginemail,
            "password": req.body.loginpassword
        },
        json: true,
        headers: req.headers
    };
    request(options, function(error, response, body) {

        console.log(body);

    });

};

I am getting the following error when I try to pass the header information in to the request module. 当我尝试将标题信息传递到请求模块时,出现以下错误。 Basically what I am trying to achieve is to pass the cookie information to the API call: 基本上,我想要实现的是将cookie信息传递给API调用:

TypeError: undefined is not a function
   at rfc3986 (E:\nodeui\webui\node_modules\request\request.js:234:14)
   at Request.json (E:\nodeui\webui\node_modules\request\request.js:1357:21)
   at Request.init (E:\nodeui\webui\node_modules\request\request.js:599:10)
   at new Request (E:\nodeui\webui\node_modules\request\request.js:272:8)
   at request (E:\nodeui\webui\node_modules\request\index.js:56:10)
   at exports.loginUser (E:\nodeui\webui\app\controllers\user.js:27:6)
   at Layer.handle [as handle_request] (E:\nodeui\webui\node_modules\express\lib\router\layer.js:82:5)
   at next (E:\nodeui\webui\node_modules\express\lib\router\route.js:110:13)
   at Route.dispatch (E:\nodeui\webui\node_modules\express\lib\router\route.js:91:3)
   at Layer.handle [as handle_request] (E:\nodeui\webui\node_modules\express\lib\router\layer.js:82:5)
exports.loginUser = function(req, res) {

    console.log(req.body.loginemail);
    console.log(req.body.loginpassword);

    var options = {
        uri: webServiceURL.login,
        method: "POST",
        body: JSON.stringify({
            "login": req.body.loginemail,
            "password": req.body.loginpassword
        }),
        json: true,
        headers: req.headers
    };
    request(options, function(error, response, body) {

        console.log(body);

    });

};

you have to change 你必须改变

body : {"login": req.body.loginemail,"password": req.body.loginpassword}

to

body : JSON.stringify({"login": req.body.loginemail,"password": req.body.loginpassword})

Try and comment the result 尝试对结果发表评论

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试在“node.js”中运行这行代码时,我收到以下错误 - When I try to run this line of code in “node.js”, I am getting the following error 从数组中获取变量,然后在 nodejs 请求模块上传递给 url - Getting variable from array then pass to url on nodejs request module 当我尝试访问它时无法访问反应道具数据。 获取 TypeError 错误 - Can not access react props data when I try to access it. Getting TypeError error 当我尝试使用ngIf运行方法时,获取“ERROR TypeError:jit_nodeValue_6(...)不是函数” - Getting “ERROR TypeError: jit_nodeValue_6(…) is not a function” when I try to run a method with ngIf 我可以在NodeJS中正确使用请求模块吗? - Am I correctly using the request module in NodeJS? 当我尝试连接到我的数据库 nodejs 时,我收到一个未知的数据库错误 - Im getting a unknown database error when i try to connect to my database nodejs 使用 reactjs 钩子时,为什么会出现“TypeError: react__WEBPACK_IMPORTED_MODULE_1___default.a.useState is not a function”错误? - Why am I getting "TypeError: react__WEBPACK_IMPORTED_MODULE_1___default.a.useState is not a function" error when using reactjs hooks? 收到未捕获的TypeError:当我尝试在按钮中使用.tableExport时 - Getting an Uncaught TypeError: when i try to use my .tableExport in a button 使用代理时如何停止NodeJS“请求”模块更改请求 - How to stop NodeJS "Request" module changes request when using proxy 我不断收到以下错误:“错误:找不到模块'./framer'” - I keep getting the following error: “Error: Cannot find module './framer'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM