无法从react native向flas发送数据

2024-10-02 10:29:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用以下代码发送数据:

        let data = new FormData();
        data.append("username", userName);
        console.log(data)
        var fetchOptions = {
          method: 'POST',
          headers: {
             "Accept": "application/json",
             'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
             'mode': 'no-cors',
             'cache': 'no-cache'
          },
          body: data
        }
        fetch(url, fetchOptions)
        .then((response) => {
          if (response.ok) {  
            responseJson = response.json();
            console.log(responseJson, response.status);
            if (response.status == 200) {
              alert('success!');
              this.state.code = false;
            }
          }
        })
        .catch((error) => {
          console.error(error);
        });

在烧瓶里我收到的数据是

^{pr2}$

但这没用。它返回console.log(responseJson, response.status);的以下内容

Promise {
  "_40": 0,
  "_55": null,
  "_65": 0,
  "_72": null,
} 200

你知道为什么会这样吗?在


Tags: no代码logjsoncachedataifapplication

热门问题