【问题标题】:Problem in fetching data to a database in react-native. Error: "json parse error unrecognized token '<' "在 react-native 中将数据提取到数据库时出现问题。错误:“json parse error unrecognized token '<'”
【发布时间】:2020-02-12 06:30:40
【问题描述】:
try {
         return fetch('http://mylinktoAPI', {
              method: 'POST',
              headers: {
                  'Accept': 'application/json',
                  'Content-Type': 'application/x-www-form-urlencoded',
              },
              body: JSON.stringify({
                  first_name: this.state.first_name,

                  last_name: this.state.last_name,

                  gender: this.state.gender,

                  blood_group: this.state.blood_group,

                  phone: this.phone,

                  email: this.email,

                  address: this.address,

              }),

          }).then((response) => response.json())
              .then((responseJson) => {
              Alert.alert(responseJson);
          }).catch((error) => {
              console.error(error);
          });
      } catch (e) {
          console.error('fetch catch error', e);
      }
};

【问题讨论】:

标签: api react-native fetch


【解决方案1】:

在headers中,可以尝试将Content-Type改为"application/json"

"Content-Type", "application/json"

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2021-07-09
    • 2019-07-12
    • 2020-07-03
    • 2019-10-05
    • 2022-07-05
    相关资源
    最近更新 更多