当我在 node.js 服务器中使用请求模块时,我遇到了一些问题,例如等待和返回。
我想在 requestController 接收“responseObject”值。
为了解决这个问题,我搜索了最好的方法,但仍然没有找到。
如何解决这个问题?
预先感谢!!:)
================================================== ========================
var requestToServer = require('request');
function getRequest(requestObject) {
var urlInformation = requestObject['urlInformation'];
var headerInformation = requestObject['headerInformation'];
var jsonObject = new Object( );
// Creating the dynamic body set
for(var i = 0; i < headerInformation.length; i++)
jsonObject[headerInformation[i]['headerName']] = headerInformation[i]['headerValue'];
requestToServer({
url : urlInformation,
method : 'GET',
headers : jsonObject
}, function(error, response ,body) {
// todo response controlling
var responseObject = response.headers;
responseObject.body = body;
});
}
// Controlling the …Run Code Online (Sandbox Code Playgroud) 我是npm的新手.我想用npm创建用户名密码.
这是我的代码:
abhi@abhi-Lenovo-Z50-70:~/Desktop/CSS_HTML/With_JS$ npm adduser
Username: abhishek
Password:
Email: (this IS public) parikh5555@gmail.com
Run Code Online (Sandbox Code Playgroud)
npm WARN adduser用户名或密码不正确
npm WARN adduser你可以通过访问来重置你的帐户:npm WARN adduser
npm WARN adduser https://npmjs.org/forgot npm WARN adduser
npm ERR!Linux 3.13.0-24-generic
npm ERR!argv"/ usr/local/bin/node""/ usr/local/bin/npm""adduser"
npm ERR!节点v6.3.1
npm ERR!npm v3.10.3 npm ERR!代码E401
npm ERR!注册表在http://registry.npmjs.org/-/user/org.couchdb.user:abhishek上为PUT返回401
我正在创建一个每隔一段时间刷新一次数据的函数,而且我遇到了我的请求链问题.问题是我有一个for循环运行异步请求,for循环将在请求完成之前完成.
setInterval(function(){ // this updates the total hours of all members every 10 seconds
request({ // this gets all of the loyalty program members
url: "",//omitted
method: "GET"
},
function(listError, listResponse, listBody) {
if(listError == null && listResponse.statusCode == 200) {
var varBody = {};
var listObj = JSON.parse(listBody);
for(var i = 0; i < listObj.result.length; i++) { // parses through all of the members to update their hours
console.log(i);//****PRINT STATEMENT
varBody.index = i;
varBody.memberID = listObj.result[i].program_member.id;
request({ //we do …Run Code Online (Sandbox Code Playgroud) 我grant_type按照文档所示将参数放入请求正文中,但 Microsoft Graph 仍然抱怨它不存在;
const tokenRequestBody = [
"grant_type=client_credentials",
"scope=https%3A%2F%2Fgraph.microsoft.com%2F.default",
`client_secret=${config.appClient.password}`
].join("&");
request.post(
{
url: tokenRequestUrl,
json: true,
headers: {
"content-type": "application/application/x-www-form-urlencoded"
},
body: tokenRequestBody
},
(err, req, body) => {
console.log(body.error_description);
// Logs: The request body must contain the following parameter: 'grant_type'.
}
);
Run Code Online (Sandbox Code Playgroud) httprequest node.js oauth-2.0 npm-request microsoft-graph-api
当使用NPM请求模块的request.defaults API时,是否有人知道我可以将一个函数作为请求头传递,以便每次发出传出请求时函数的结果都成为头值?
即
request.defaults({
headers:{datestamp:() => new Date()
})
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
let request = require('request');
let fs = require('fs');
request.get('http://localhost:8080/report.rtf')
.pipe(fs.createWriteStream(__dirname + '/savedDoc.rtf'));
Run Code Online (Sandbox Code Playgroud)
它运行良好,但前提是文档从给定的 URL 成功下载。但是,如果有任何 HTTP: 403、404 或任何其他错误,则会保存一个长度为零的空文件!
我怎么能.pipe()只在 HTTP: 200 响应的情况下而不使用任何额外的 HEAD 请求?应该可以一口气搞定!
$ npm login --scope=@username --registry=https://npm.pkg.github.com
$ Username: username
$ Password: ********
$ Email: (this IS public) example@gmail.com
$ npm ERR! code E401
$ npm ERR! 401 Unauthorized - PUT $ https://npm.pkg.github.com/-/user/org.couchdb.user:forinda - Error authenticating user: Requires authentication
$npm ERR! A complete log of this run can be found in:
$npm ERR! /home/orinda/.npm/_logs/2021-10-15T02_25_19_104Z-debug.log
Run Code Online (Sandbox Code Playgroud)
无法验证 npm 注册表和 github 我在填写密码时收到 401 错误 如何解决此问题
npm-request ×7
node.js ×6
npm ×3
javascript ×2
github ×1
httprequest ×1
node-streams ×1
npm-publish ×1
oauth-2.0 ×1
request ×1
ubuntu ×1