多个axios请求怎么按顺序实现?我写的是哪里出问题了,打印的res值都是来自第一个post请求的返回结果,第二个get请求里的res值没有获取到?
axios({
method: 'POST',
url: 'https://openspeech.bytedance.com/api/v1/tts_async/submit',
headers: {
'Content-Type': 'application/json',
'Resource-Id': 'volc.tts_async.default',
'Authorization': 'Bearer;CiWImuQXN_xzNTZ5YyC5r'
},
data: {
"appid": "5565218",
"reqid": nanoid(30),
"text": '这是一段测试文字!',
"format": "wav",
"voice_type": "BV705_streaming"
}
}).then(function (res) {
console.log('post', res.data)
return axios({
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Resource-Id': 'volc.tts_async.default',
'Authorization': 'Bearer;CiWI1f4XN_xzNTZ5YyC5r'
},
url: `https://openspeech.bytedance.com/api/v1/tts_async/query?appid=5568&task_id=${res.data.task_id}`
})
}).then(function (res) {
console.log('get', res.data)
}).catch(err => {
console.log('get:err')
})
把第二个then放里面也是一样,
axios({
method: 'POST',
url: 'https://openspeech.bytedance.com/api/v1/tts_async/submit',
headers: {
'Content-Type': 'application/json',
'Resource-Id': 'volc.tts_async.default',
'Authorization': 'Bearer;CiWImuQZhWXN_xzNTZ5YyC5r'
},
data: {
"appid": "556218",
"reqid": nanoid(30),
"text": '这是一段测试文字!',
"format": "wav",
"voice_type": "BV705_streaming"
}
}).then(function (res) {
console.log('post', res.data)
axios({
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Resource-Id': 'volc.tts_async.default',
'Authorization': 'Bearer;CiWImuQC1f4XN_xzNTZ5YyC5r'
},
url: `https://openspeech.bytedance.com/api/v1/tts_async/query?appid=556218&task_id=${res.data.task_id}`
}).then(function (res) {
console.log('get', res.data)
})
}).catch(function (err) {
console.log(err)
})
前端新手,请多指教
你的第二个axios的then在哪儿呢。。。
这样坑定没有第二个请求的结果打印啊