【发布时间】:2017-08-26 10:31:15
【问题描述】:
我正在使用 mocha 来获取此 API 的响应:“http://reqres.in/api/users?page=1”
但是,当在 mocha 中使用相同的请求来获得响应时(在这种情况下是令牌)。我得到一个空的回复。 以下是我编写的代码和终端中的输出:
const mocha = require ('mocha');
const should = require ('should');
const supertest = require('supertest');
let baseUrl = supertest("http://reqres.in/");
let listUserEndPoint = 'api/users?page=1';
it("List User", async function() {
let res = await baseUrl.get(listUserEndPoint)
.set('Content-Type', 'application/json') // Setting the content type as header
console.log(res.body);
});
谁能帮帮我,我做错了什么?
【问题讨论】:
-
您没有指定任何标题。那你应该怎么登录?我猜如果你在控制台的响应对象上吐出标题,你会看到类似 HTTP 400 Forbidden 响应。
-
@oligofren 感谢您指出这一点,该 API 通过设置标题来工作,但是我已经编辑了我的问题,即使在设置标题后,这个 API 仍然给出一个空响应,你能帮帮我吗!