gpt4 book ai didi

javascript - 如何手动创建 multipart/form-data

转载 作者:数据小太阳 更新时间:2023-10-29 06:00:04 24 4
gpt4 key购买 nike

最佳答案

您可以像本例一样使用 XMLHttpRequest 手动创建 multipart/form-data

function multiPost(method, url, formHash){
var boundary = "nVenJ7H4puv"
var body = ""
for(var key in formHash){
body += "--" + boundary
+ "\r\nContent-Disposition: form-data; name=" + formHash[key].name
+ "\r\nContent-type: " + formHash[key].type
+ "\r\n\r\n" + formHash[key].value + "\r\n"
}
body += "--" + boundary + "--\r\n"

var xml = new XMLHttpRequest();
xml.open(method, url)
xml.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary)
xml.setRequestHeader("Content-Length", body.length)
xml.send(body)
}

关于javascript - 如何手动创建 multipart/form-data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47080869/

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