[英]How to set cookie for localhost to test API in NodeJS?
I have a web application and I'm writing APIs on NodeJS. 我有一个Web应用程序,并且正在NodeJS上编写API。
I want to test this APIs use mocha, chai and Node-rest-client and don't open browser, but I have a problem: " I don't know How to set cookie (Authorization of header) when I ran server on localhost ) 我想使用mocha,chai和Node-rest-client测试此API,并且不打开浏览器,但是我遇到一个问题:“ 当我在本地主机上运行服务器时,我不知道如何设置cookie(标头的授权) )
If you're using chrome it usuall wont save cookies for loacal host try running the following to run chrome with disabled web security. 如果您使用的是chrome,通常不会为本地主机保存cookie,请尝试运行以下命令以在禁用网络安全的情况下运行chrome。
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir="C:/Chrome dev session" --args --disable-web-security
UPDATE UPDATE
As in the documentation you can set Auth header with this : Documentation 如文档中你可以设置验证标头是: 文档
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.