【问题标题】:superagent-bluebird-promise cannot GETsuperagent-bluebird-promise 无法获取
【发布时间】:2015-10-16 00:40:10
【问题描述】:

我正在使用 superagent-bluebird-promise,下面给出了 404 错误,“无法获取 /v1/result”。当我通过邮递员调用它时,已经确认它有效。我究竟做错了什么?

it('should return a result', function(done){
    stub.login(userId);
    request.get('http://localhost:8080/v1/result/')
    .then(function(res) {
        console.log(res);
        expect(res.body).to.have.lengthOf(1);
    }, function(error) {
        console.log(error);
        expect(error).to.not.exist;
    })
    .finally(function(){
        stub.logout();
        done();
    });         
});

【问题讨论】:

  • login 是异步的吗?如果您已注销,您会看到该页面吗?
  • 如果我注释掉 stub.login(),我会得到相同的结果。 (直播,如果我不登录,我会得到 401 而不是 404)。

标签: promise bluebird superagent


【解决方案1】:

superagent-bluebird-promise 基于 supertest

假设 stub.login 设置了一些 cookie,那么您将在下一个请求中需要它们。

为此,您需要一个代理。 (应用程序可能是可选的)

var agent = request.agent(app) agent.request(...)

在代理上执行登录,然后在其上执行请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 2018-04-12
    • 2018-07-06
    相关资源
    最近更新 更多