【发布时间】:2019-09-27 06:55:27
【问题描述】:
我正在尝试以本机反应发送多部分请求。我尝试了很多方法,但都没有奏效。请检查此示例。
const data ={
"person": this.state.person,
"email": this.state.email,
"password":this.state.password,
"confirmPassword":this.state.confirmPassword,
"otp": {
"secret":this.state.otp
},
}
RNFetchBlob.fetch('POST', '${server}api/user-registration/register', {
'Content-Type' : 'multipart/form-data',
}, [
{
name:"data",data:JSON.stringify(data)
}
]).then((resp) => {
console.log(resp)
}).catch((err) => {
console.log(err)
})
我收到 415 作为响应。看起来它没有将 multipart/form-data 放在 Headers 中。
我已经用 Reactjs 试过了,它完全可以工作。 这是 Reactjs 中的一个示例。
const eventData = new FormData();
eventData.append('data', new Blob([JSON.stringify(data)], { type: "application/json" }));
axios.post('${server}api/user-registration/register',eventData,{headers:{}})
任何人都可以看到 RNFetchBlob 代码的任何问题吗?
【问题讨论】:
标签: react-native blob fetch multipart