3 回答
TA贡献1813条经验 获得超2个赞
let formData = new FormData();
formData.append('image', {uri: image.uri, type: 'image/jpg', name: 'image.jpg'});
formData.append('description', String(data.description));
let options = {};
options.headers['Content-Type'] = 'multipart/form-data; boundary=6ff46e0b6b5148d984f148b6542e5a5d';
options.body = formData;
return fetch(uri, options).then((response) => {
....
});
只要把body从Json换成FromData就可以了
TA贡献1890条经验 获得超9个赞
method: 'POST',
headers: {
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue',
})
})123456789
默认发送’Content-Type’: ‘application/json’ 的请求,但是现在想发送Form表单,该怎么写尼?
let formData = new FormData();
formData.append('image', {uri: image.uri, type: 'image/jpg', name: 'image.jpg'});
formData.append('description', String(data.description));
let options = {};
options.headers['Content-Type'] = 'multipart/form-data; boundary=6ff46e0b6b5148d984f148b6542e5a5d';
options.body = formData;
return fetch(uri, options).then((response) => {
....
});12345678910
只要把body从Json换成FromData就可以了,解决完问题然后下班的感觉真好。
- 3 回答
- 0 关注
- 2101 浏览
添加回答
举报