我是react app的新手。我正在获取基于一些参数的数据细节,如开始日期,结束日期和序列号。我正在传递多个序列号,用逗号值在使用axios的字符串中分隔。get方法。我的查询如下:
var formattedstartTime = moment(startTime)
.utc()
.format()
.toString();
var formattedendTime = moment(endTime)
.utc()
.format()
.toString();
const modemSerialsValues = networks.map((p) => p.modemSerial).join(",");
//const modemSerialsValues="161887,162181,136787,141300,153700,156282,160219,157249,160124,204883,204707,209266,156881,157944,157532,208788,137311,157971,160131,208972,162157,153436,209377,160010,204915,162045,131292,160136,160014,204630,209508,235133,130508,209413,160078,204949,159977,236148,204718,137920,171014,160110,161295,157706,160185,130220,74699,130033,224303,272,153264,136696,129740,162017,153243,160017,159743,132118,157570,160180,159942,154105,155613,156030,161283,155940,74931,136773,159732,157694,161153,160089,156202,204859,209440,230476,131772,160176,156795,209514,130401,209445,224114,156243,235016,209224,130436,159927,223996,161813,70932,209292,136529,209172,209397,160111,72434,209281,161441,136556,136794,160040,162023,153160,156315,158076,152777,171375,224297,224277,70704,129496,224220,224220,159856,209418,74575,156908,84691,70704,157856,70912";
useEffect(() => {
dispatch(setPerformanceLvls(null));
axios
.get(
config.API_PERFORMACE + `/${formattedstartTime},${formattedendTime}`,
{ data: '"' + modemSerialsValues + '"' }
)
.then((res) => {
const pd: PerfomanceData[] = res.data;
console.log("++++++++++++Pd+++++++++++++");
console.log(pd);
console.log("++++++++++++Pd+++++++++++++");
const pdMap = pd.reduce((acc, curr) => {
acc[curr.deviceSerialNumber] = curr;
return acc;
}, {});
setData(pdMap);
const plvlMap = pd.reduce((acc, curr) => {
acc[curr.deviceSerialNumber] = curr.perfomanceLevel;
return acc;
}, {});
console.log(plvlMap);
dispatch(setPerformanceLvls(plvlMap));
setDataFetched(true);
console.log(pdMap);
})
.catch((error) => {
console.log("can not load data");
//setErrorMessages(["Cannot load data"])
//setIserror(true)
});
}, [dispatch, endTime, formattedendTime, formattedstartTime, modemSerialsValues, startTime]);
**但是得到204,我不知道为什么,它花了更多的时间。理想情况下,它应该在几毫秒内调用,但需要近20分钟才能获得204值。**
我也试着通过邮寄来获取数据,但时间是主要问题。
204并不意味着它失败了。意思是没有内容。所以也许你在后台犯了一个错误…