nextjs httpService将带有变量数据的post发送到API

eblbsuwk  于 2023-04-20  发布在  其他
关注(0)|答案(1)|浏览(140)

我想从nestjs调用https://www.one-dc.com/ao/上的一个端点。我目前收到错误消息:data 13 - XML标签应该在POST变量“data”中给出

const { data } = await firstValueFrom(
  this.httpService
    .post(process.env.EDC_ORDER_URL, { data: xmlOutput })
    .pipe(
      catchError((error: AxiosError) => {
        this.logger.log('Axios error')
        this.logger.error(error.response.data);
        throw 'An error happened!';
      }),
    ),
);
console.log(data);

响应来自

rjjhvcjd

rjjhvcjd1#

我使用以下方法解决了这个问题:

const url = require('url');
const params = new url.URLSearchParams({
  data: xmlOutput,
});
const { data } = await firstValueFrom(
  this.httpService.post(process.env.EDC_ORDER_URL, params.toString()).pipe(
    catchError((error: AxiosError) => {
      this.logger.error(error.response.data);
      throw 'An error happened!';
    }),
  ),
);

相关问题