gpt4 book ai didi

react-native - react native 后嵌套表单数据

转载 作者:行者123 更新时间:2023-12-04 04:09:52 32 4
gpt4 key购买 nike

我正在尝试使用 formdata 发布嵌套值。我是这样尝试的:

const {phone} = this.state

let formdata1 = new FormData();
let formdata2 = new FormData();
let formdata3 = new FormData();

formdata1.append("0","h23")
formdata2.append("address1",formdata1)
formdata2.append("use_for_shipping",true)
formdata2.append("first_name","isa")
formdata2.append("last_name","annamyradow")
formdata2.append("email","isaanna98@gmai.com")
formdata2.append("city","ashgabat")
formdata2.append("state","TKM")
formdata2.append("postcode","110092")
formdata2.append("country","TKM")
formdata2.append("phone",{phone})

formdata3.append("billing", formdata2)

console.warn(JSON.stringify(formdata2))

fetch(`http://arzan.com.tm/market/api/checkout/save-address`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: formdata2



})

.then((response) => response.json())
.then((res) => {
console.warn('zakaz: '+JSON.stringify(res))
})
}

在react-native中我从来没有遇到过这种对象结构。我根据我对formdata的推断尝试了一下。我知道有一些不足。实际发布的数据结构应该是这样的:

{
"billing" : {
"address1" : { "0" : "h23" },
"use_for_shipping" : "true",
"first_name" : "john",
"last_name" : "doe",
"email" : "john@webkul.com",
"city" : "noida",
"state" :"DL",
"postcode" : "110092",
"country" : "IN",
"phone" : "8802097347"
},
"shipping" : {
"address1" : {
"0" : ""
}
}
}

它给出了 Unhadled Promise Rejection。有人可以帮我吗?

最佳答案

您使用了错误的内容类型来发送表单数据,表单数据的内容类型应该是“multipart/form-data”,而不是“application/json”。还可以考虑将数据作为 json 发送。

关于react-native - react native 后嵌套表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61911309/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com