亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何檢查獲取響應以調用另一個響應?

如何檢查獲取響應以調用另一個響應?

呼啦一陣風 2021-07-02 10:03:16
我試圖從 API 下載 json 文件。為此,我需要調用 3 個端點。http://url.com/export它返回一個json: {"exportLoading":true,"file":"export-20190618-183316.json"}之后,我應該調用第二個端點并檢查此導出的狀態:http://url.com/export/status它返回trueor false(當服務器正在處理時,此端點返回true。當它返回false文件時,文件已完成下載。)因此,如果status === false, 我可以調用最后一個端點 http://url.com/download/file_name(我使此請求傳遞文件名 - 從第一個請求返回 - 以下載文件。我的問題是,如何檢查第二個端點是否返回false以發出最后一個請求并下載文件?我只是這樣做,直到第二個端點。app.get('/export', function (req, res, next) {    global.fetch = fetch    global.Headers = fetch.Headers;    const headers = new Headers();    const username = 'user';    const password = 'pass';    const URL = 'http://url.com/export'    headers.set('Authorization', 'Basic ' + base64.encode(username + ":" + password));    fetch(URL, {        method: 'GET',        headers: headers,    })    .then(res => res.json())         .then(json => {                        fetch("http://url.com/exportl/status", {             method: 'GET',            headers: headers,        }).then(result => ...)     })    .catch(function (error) {        console.log(error)      }) });
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號