Tag: axios

Axios获取请求超时被吞噬(Promise)

我一直在研究这个数据收集模块,这个模块应该是从不同的比特币市场获得数据,并将所有接收到的数据标准化,以便将其插入到mongodb数据库中供以后使用。 (该模块是在节点4.3.x中编写的) 我遇到的问题是我需要在数据库中表示数据的一致性。 所以,每当一个请求超时,而不是捕获获取请求并logging一个错误,我想parsing一个'0'。 此外,收到的数据包含需要按顺序切割的交易。 这需要发生,以便交易可以正确地切割,所以数据不会被写两次。 为此,我实施了两个队列: 1:TimestampQueue – 保存时间戳。 下一个预期的响应是[0]中的时间戳 2:objectQueue – 保存收到的响应 =>只要objectQueue [0]中的对象等于timestampQueue [0] =>中的时间戳,就执行数据操作并插入到数据库中。 问题在于,应该捕获超时的axios.get请求并不一致。 它发生在随机的时间框架之后,但平均而言,队列在2小时之后就会卡住了。 为了使这里更清楚一些重要的代码片段:httpclient使axios请求: get(url) { return this.instance.get(url) //instance just defined a timeout. Nothing special .then(response => { return response.data; }) .catch(error => { throw error; //THIS SEEMINGLY DOESN'T GET EXECUTED IN THE DESCRIBED CASE }); } 现在解决请求的市场处理者: […]

通过POST将文件传递给NodeJS,然后传递到另一个API而不保存在磁盘上

我需要从React UI(使用axios)接收用户的文件,通过POST使用Express将这个文件发送到NodeJS方法,然后我需要通过POST直接将这个文件发送到另一个API(.NET WebAPI)而不保存在磁盘上。 我试图直接传递数据文件(req.files.file.data),但.NET API无法识别请求中的文件。 有没有可能在“var”中创build一个临时文件并像我一样从磁盘读取文件时发送它? 这个例子适用于本地文件: var formData = { form: "{ abn: '666666666' }", files: JSON.stringify([ { name: "file1", type: "1", number: "6666" }, { name: "file2", type: "3", number: "3333" }, ]), // Pass multiple values /w an Array attachments: [ fs.createReadStream(__dirname + '/../file1.txt'), fs.createReadStream(__dirname + '/../file2.txt') ], }; var reqs = […]

将缓冲区对象发回给Axios会导致错误

我创build了一个lambda函数在S3中添加的每个对象上执行。 我需要将每个文件转发到另一台服务器。 从S3中检索到的对象types是: { AcceptRanges: 'bytes', LastModified: 2017-05-29T18:29:47.000Z, ContentLength: 22502, ETag: '"9eff66fa38994b09e8f2072a79044734"', ContentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', Metadata: {}, Body: <Buffer 50 4b 03 04 14 00 06 00 08 00 00 00 21 00 71 d0 15 40 bc 01 00 00 de 09 00 00 13 00 08 02 5b 43 6f 6e 74 65 6e […]

如何使用axios将string发送到快速服务器

我是新来的网页开发,所以任何帮助,非常感谢。 我需要发送一个纯文本到服务器,所以我可以将MathJax应用到它。 sendForTeX (text) { console.log('Sending ' + text + ' to be converted to LaTeX…') axios.post('/tolatex', text) .then(function (response) { console.log(response) }) .catch(function (error) { console.log(error) }) } 在服务器端,我首先使用body-parser app.use(bodyParser.urlencoded({ extended: false })) 然后,我定义一个中间件来排版文本。 function toLatex (req, res, next) { console.log(req.body) MathJax.typeset({ math: req.body, format: 'TeX', svg: true, mml:false, }, function (data) { if […]

处理102在Node.js中的状态(处理)

我从我的服务器(Node8.9.0LTS)发出一个请求到其他服务,我收到一个102 processing状态代码: const firstRes = await ajaxService.post('/data/search', params) <– issue a request with a timeout –> ctx.data = secondRes.response.data //return the response to the client ajaxService返回一个使用axios发出请求的asynchronous函数。 我如何编写代码发出相同的请求,间隔1秒,限制为5秒(所以我会返回超时到客户端)与asynchronous/等待?

使用Axios或获取自己的REST Api节点内调用吗?

我设立了几个用express来做某些事情的端点。 现在理想情况下,我想从节点应用程序中调用它们来处理一些数据。 有没有办法从节点实例中自己调用apis?

如何通过API发布主旨(不是匿名的)

我正在使用passport-github策略。 passport.use(new Strategy({ clientID: "…", clientSecret: "…", callbackURL: 'http://localhost:3000/login/github/return', scope: 'gist' }, function(accessToken, refreshToken, profile, cb) { return cb(null, profile); })); 然后我发出POST请求 app.get('/profile/post', require('connect-ensure-login').ensureLoggedIn(), function(req, res){ var url = 'https://api.github.com/gists'; axios.post(url, { method: "POST", "description": "POSTING FROM EXPRESS", "public": true, "files": { "file1.txt": { "content": "EXPRESS " } } }) .then(function (response) {…}) .catch(function (error) […]

Axios与node.js – ReferenceError:XMLHttpRequest未定义

我从一个简单configuration的axios实例触发一个GET请求: var Axios = axios.create({ baseURL: myBaseUrl, headers: {'content-type': 'application/json'} }); Axios.get(url) 并得到以下错误: ReferenceError: XMLHttpRequest is not defined at dispatchXhrRequest (C:\…\node_modules\axios\dist\axios.js:804:24) at xhrAdapter (C:\…\node_modules\axios\dist\axios.js:796:11) at process._tickCallback (internal/process/next_tick.js:103:7) at Function.Module.runMain (module.js:577:11) at startup (node.js:160:18) at node.js:456:3 据我的理解(并根据文档 ),axios应该在web浏览器和node.js上工作。 我错过了什么? 版本: node – 6.2.1 axios – 0.13.1

发送后无法设置标题…没有问题,直到我join了身份validation?

我遇到了一些问题,试图从我的应用程序发送自定义标头的axios请求,所以我可以使用它们在我的服务器上进行身份validation。 我有一个使用Firebase身份validation和节点/快递后端服务器的原生应用程序。 当用户login时,我会抓住他们的firebase idtoken并存储它。 然后,只要我向服务器发出axios请求,我就会把这个idtoken作为头文件发送出去。 const { currentUser } = firebase.auth(); const url = ${serverUrl}/api/users/${user.uid`; const idtoken = await currentUser.getToken(true); var config = { headers: { idtoken }, }; const response = await axios(url, config); 在服务器代码中,将会有一个快速中间件来检查请求头中发送的idtoken是否有效。 如果是,它将调用next()并继续执行逻辑。 如果没有,那么它会失败并发送401状态。 这是在我的app.js : const app = express(); app.use(bodyParser.json()); app.use(firebaseAuthentication); router(app); 这是firebaseAuthentication中间件: const firebaseAuthentication = async (req, res, next) […]

Axios GET请求不起作用

我正在使用:Axios:0.17.1节点:8.0.0 以下标准节点得到正常工作,但Axios版本没有。 任何想法为什么? 节点http: http .get(`${someUrl}`, response => { buildResponse(response).then(results => res.send(results)); }) .on('error', e => { console.error(`Got error: ${e.message}`); }); 爱可信: axios .get(`${someUrl}`) .then(function(response) { buildResponse(response).then(results => res.send(results)); }) .catch(function(error) { handleError(error, res); }); 我只是得到一个503的捕获,“请求失败,状态码503”