浏览器console发送post请求

发布时间 2023-05-17 00:33:33作者: Peter.Jones
const text = `
18  0.5 18
19  0.5S  19
20  1 20
21  2 21
22  3 22
23  0.25  23
24  1.5 24
25  2.5 25
26  3.5 26
27  5 27
28  10  28
29  20  29
30  A级  30
31  B级  31
32  C级  32
33  D级  33
34  E级  34
35  0.2SS 35
36  0.5SS 36
99  其他  99
`;

const arr = text.split("\n").filter(v => !!v).map(v => ({
  code: v.split("\t")[0],
  value: v.split("\t")[1]
}));

for (let i = 0; i < arr.length; i++) {
  const d = arr[i];
  fetch("http://localhost:30376/api/sysDictData/add", {
    "headers": {
      "accept": "application/json, text/plain, */*",
      "accept-language": "zh-CN,zh;q=0.9",
      "authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjEsImFjY291bnQiOiJzdXBlckFkbWluIiwidXVpZCI6ImVjZTVhZWY3LWZiNzktNDRhNC1iZWVjLTU2NjhiOGE1MzExMiIsInN1YiI6IjEiLCJpYXQiOjE2ODQxMjM1MTQsImV4cCI6MTY4NTIwOTkxNH0.MUyaSQ5X9YpoT4z03PQW389eme-XkBkI_FAwugtKghI2VbvadDoLAoZoj9zx7emriaTG4_wauXHlRlxFqqCI8Q",
      "content-type": "application/json;charset=UTF-8"
    },
    "referrer": "http://localhost:30376/dict",
    "referrerPolicy": "strict-origin-when-cross-origin",
    "body": `{"typeId":"1432639879270391809","value":"${d.value}","code":"${d.code}","sort":100 }`,
    "method": "POST",
    "mode": "cors",
    "credentials": "include"
  });
}