如何用React-Native Post Form 表单
发布时间:2020-12-15 04:41:06 所属栏目:百科 来源:网络整理
导读:今天使用react native 发送请求的时候,发现使用 fetch( 'https://mywebsite.com/endpoint/' ,{ method: 'POST' ,headers: { },body: JSON. stringify({ firstParam: 'yourValue' ,secondParam: 'yourOtherValue' ,}) }) 默认发送’Content-Type’: ‘applic
今天使用react native 发送请求的时候,发现使用 fetch('https://mywebsite.com/endpoint/',{ method: 'POST',headers: { },body: JSON.stringify({ firstParam: 'yourValue',secondParam: 'yourOtherValue',}) })
默认发送’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) => { .... });
只要把body从Json换成FromData就可以了,解决完问题然后下班的感觉真好。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |