如何修复axios中的不可处理实体错误

时间:2019-05-06 06:31:00

标签: javascript post axios

我正在尝试使用axios发出发布请求,但始终收到不可处理的实体错误。如何获取正确的数据格式?

即使尝试对数据进行字符串化处理,我仍然会收到此错误。

分别是我的axios发布请求和数据示例:

try {

           let i = 0;
           transactionObject = JSON.stringify(transactionArray[i], null, 4)
           let intervalId = setInterval(function() {
             console.clear();
             if (i === 50) {
               clearInterval(intervalId);
               console.log(
                 `- transaction collation completed\n`
               );
             }
             axios({
               url: url,
               method: "POST",
               data: transactionArray[i]
             })
               .then(function(res) {
                 console.log(res.data);
               })
               .catch(function(error) {
                 console.error(error);
               });
             console.log(`${i} post(s) sent \n`);

             i++;
           }, 10000);

} catch (error) {
    console.log(error)
}data: '{"BuildingName":"MMU - Cyberjaya 2 (old bin)","CollectionDate":"2018-06-22T04:03:39.319Z","CollectionName":"iCycle","TimeCycle":"2018-06-22T04:10:47.975Z","TotalWeight":3,"Co2WeightInKG":1.6800000000000002,"RecyclPoints":4.8,"ItemName":"cardboard","ItemType":"Paper products","vendortoken":"fMqP4XDGU8mUmLV4AfF"}' 

我希望发送请求,但是我不断收到Unprocessable实体错误。该错误的状态码为422

0 个答案:

没有答案