本机HTTP发布请求发送空数据

时间:2019-08-17 07:35:10

标签: node.js angular express ionic4 ionic-native

当我尝试从Ionic 4反应性表单数据向服务器发送发布请求时,我收到状态码为200的响应。但是当我尝试从服务器获取详细信息时,所有均为空值。我不明白我在哪里犯错。

我也尝试过在发送给服务器之前对对象进行字符串化处理。但是同样的问题。请让我知道我在哪里弄错了。谢谢。

客户端代码:

uploadSendingRules() {
    const sendingRules = new SendingRules(this.sendingRulesForm.value.localSendBy,
      this.sendingRulesForm.value.nationalSendBy,
      this.sendingRulesForm.value.regionalSendBy,
      this.sendingRulesForm.value.internationalSendBy);
    this.saveSendingRules(sendingRules, this.authService.loggedUser.id);
  }

  async saveSendingRules(sendingRules: SendingRules, userId: number) {
    try {
      this.authService.showLoader('Updating Sending Rules...');
      const url = 'https:url-to-server/save-sending-rules';
      const params = {sendingRules, userId};
      const response = await this.http.post(url, params, this.authService.authHeaders);
      this.authService.hideLoader();
      alert(response.data);
    } catch (error) {
      this.authService.hideLoader();
      alert('error-->' + error.status);
      alert(error.data);
    }
  }

服务器端代码:

router.post('/v1/save-sending-rules',function(req,res){
        if(constants.DEBUG) console.log(req.body);
        SendConfRules.findOne({
                where : {
                    SRUL_VPUI_ID : req.body.userId
                },
                 order : [['SRUL_VPUI_ID','DESC']]
            }).then((confRules) => {
            if(confRules){
                confRules.update(dataObjects.sendingRules(req.body)).then((numRows) => {
                    res.json({
                        status : 200,
                        msg: "Rules updated"
                    });
                });
            }
            else{
                SendConfRules.create(dataObjects.sendingRules(req.body)).then(
                    (sendingRules) => {
                        res.json({
                        status : 200,
                        sendingRules : resSendingRules(confRules.dataValues)
                    });
                }).catch((err) => {logger.error(err)});
           }   
        }).catch((err) => {logger.error(err)});

    });

0 个答案:

没有答案