需要向“/...”提交POST请求,并在form-data中包含以下数据:React Native

问题描述 投票:0回答:1

需要向“/...”提交POST请求,并在form-data中包含以下数据:React Native。

 firstName: text,
 middleName: text,
 lastName: text,
 email: text,
 country: text Alpha-3 country code (e.g. EGY or DEU),
 phone: text,
 dob: text Date of birth (format YYYY-mm-dd, e.g. 2001-09-25).,
 gender: text,
form-data postdata
1个回答
0
投票

请使用FormData。

import FormData from 'FormData';

var data = new FormData();
data.append("firstname", "abc");
fetch('YOUR_URL', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'multipart/form-data',
    },
    body:data,
})
.then((response) => response.json())
.then((responseJson) => {
    console.log('response object:',responseJson)
})
.catch((error) => {
  console.error(error);
});
© www.soinside.com 2019 - 2024. All rights reserved.