|
悬赏1油猫币已解决
var 链接="http://www.chuanxincao.net/XiaoShuoAPI/EditorBook/"
var 数据 ={
"id": "0",
"bookName": "hot",
"imgUrl": "default_poster.jpg",
"bookBrief": "",
"bookType": "1",
"isEnd": "0"
}
function post3(url,jsondata){
var xhr = new XMLHttpRequest();
xhr.open('post', url, true);
var formData = new FormData();
xhr.setRequestHeader('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8');
for (var key in jsondata) {
formData.append(key, jsondata[key])
}
xhr.send(formData);
xhr.onload = function () {
if(xhr.readyState==4&&xhr.status==200){
console.log(xhr.responseText);
}
}
}
post3(链接,数据)
post发送formData数据,是像这样的,有"-----------------------------" 这样的分隔符
-----------------------------2348998176134986568069107297
Content-Disposition: form-data; name="id"
0
-----------------------------2348998176134986568069107297
Content-Disposition: form-data; name="bookName"
hot
-----------------------------2348998176134986568069107297
用GM_xmlhttpRequest 怎么能发出有分隔符的数据包呢,下面这个发出去不一样
GM_xmlhttpRequest({
method: "post",
url: 链接,
data: JSON.stringify(数据),
headers: {'Content-Type': 'multipart/form-data'},
onload: function(response) {
console.log(response.responseText)
}
}) |
最佳答案
查看完整内容
new FormData()
即可
https://developer.mozilla.org/zh ... ng_FormData_Objects
data处直接填这个
|