如何为localhost设置cookie以在nodejs中测试API



我有一个Web应用程序,我正在nodejs上编写API。

我想测试此API使用Mocha,Chai和Node-Rest-Client,并且不要打开浏览器,但是我有问题:" 我不知道如何设置cookie(授权的header(当我在localhost上运行服务器(

  • 首先,在localhost上运行服务器:3000。
  • 接下来,运行命令API测试(将cookie设置为服务器并运行API Testcase(。

如果您使用的是Chrome IT IT USUALL不会将cookie保存为loacal主机尝试运行以下操作以使用残疾Web安全性运行Chrome。

"C:Program Files (x86)GoogleChromeApplicationchrome.exe" --user-data-dir="C:/Chrome dev session" --args --disable-web-security

update

如文档中,您可以使用以下方式设置auth标题:文档

var Client = require('node-rest-client').Client;
// configure basic http auth for every request
var options_auth = { user: "admin", password: "123" };
var client = new Client(options_auth);

最新更新