首页 > 解决方案 > Need help to induction curl Post in code JS / Node.js

问题描述

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}'....

It works if I use this in the console. How can I implement this in JS code?

标签: javascriptcurlpost

解决方案


除非我对 curl 有什么遗漏,否则您可以使用 fetch 发出类似的请求:

fetch(urlToPostTo, {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({text: 'Hello, World!'})
  });


推荐阅读