gpt4 book ai didi

javascript - Node js将变量传递给请求回调函数

转载 作者:搜寻专家 更新时间:2023-10-31 23:30:33 25 4
gpt4 key购买 nike

<分区>

我希望将一个变量绑定(bind)到我的请求对象,以便在进行回调时我可以访问该变量。

这是图书馆: https://github.com/request/request

这是我的代码。

var request = require('request');    
for (i = 0; i < cars.length; i++) {


request({
headers: { 'Content-Type': 'application/json'},
uri: 'https://example.com',
method: 'POST',
body: '{"clientId": "x", "clientSecret": "y"}'
},
function(err, res, body){
// I want to put the correct i here.
// This outputs cars.length almost everytime.
console.log(i);
});

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com