简体   繁体   English

API.post()函数调用AWS SDK的检索HTTP响应

[英]Retreive HTTP Response from API.post() function call AWS SDK

I'm calling a NodeJS Lambda function from my ReactJS front-end, and I would like to retreive the http response to get the value inside. 我正在从我的ReactJS前端调用ReactJS Lambda函数,我想检索http响应以获取内部值。
My code is the following to call the AWS function, and the console.log(result) is undefined 我的代码如下以调用AWS函数,并且console.log(result)未定义

var result = await this.requestCSVDownloadURL({
                userId: this.state.userId,
                noteId: this.state.noteId
              });
    console.log(result)

The code of requestCSVDownload() is the following : requestCSVDownload()的代码如下:

requestCSVDownloadURL(jsonObject){
    if(jsonObject.userId != null && jsonObject.noteId != null){
      var result = API.post("notes", "/request-csv-url", {
        body: jsonObject
      })
    }
  }

And I receive the following HTTP response which is what I want to get the body: 我收到以下HTTP响应,这是我要获取的正文: 在此处输入图片说明

Does someone have an idea how to be able to get this http response ? 有人知道如何获得此http响应吗?

You need to access the payload property and parse the JSON response to get the body. 您需要访问有效负载属性并解析JSON响应以获取主体。

var result = await this.requestCSVDownloadURL({
                userId: this.state.userId,
                noteId: this.state.noteId
              });
    console.log(JSON.parse(result.payload).body)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM