V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xxxwyp
V2EX  ›  Node.js

新手小白求助 request 问题

  •  
  •   xxxwyp · 2018-10-12 16:58:27 +08:00 · 2551 次点击
    这是一个创建于 2012 天前的主题,其中的信息可能已经有所发展或是发生改变。
    request({
    url:"https://gzmss.iok.la/api/v2/users/signin",
    method: 'POST',
    headers: {
    "content-type": "application/json",
    },
    // body: JSON.stringify(userObj),
    body:{'password':"123456",
    'user_name':"yeungy"
    },
    json: true
    },function(error,response,body){
    console.log(body);
    })

    为什么这段代码会报 400 错误,用 postman 能通,通过 node 请求不行
    3 条回复    2018-10-15 13:45:52 +08:00
    xxxwyp
        1
    xxxwyp  
    OP
       2018-10-12 16:59:30 +08:00
    在线等,期待大神稍微抽点时间帮忙解决,抽感激不尽!
    Debiancc
        2
    Debiancc  
       2018-10-15 09:41:47 +08:00
    400 错误贴一下
    liliya
        3
    liliya  
       2018-10-15 13:45:52 +08:00
    var request = require("request");

    var options = { method: 'POST',
    url: 'https://gzmss.iok.la/api/v2/users/signin',
    headers:
    {
    'content-type': 'application/x-www-form-urlencoded' },
    form: { user_name: 'yeungy', password: '123456' } };

    request(options, function (error, response, body) {
    if (error) throw new Error(error);

    console.log(body);
    });
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3611 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:52 · PVG 12:52 · LAX 21:52 · JFK 00:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.