将cURL请求转换为Axios帖子

时间:2019-08-06 16:01:10

标签: http curl axios prometheus

我正在使用prometheus pushgateway库,但无法向其发送信息。这些示例使用了很好的cURL,但是当我尝试在节点程序中对AXIOS进行等效处理时,会引发错误。

我尝试设置快递服务器以将相同的请求发送到。我想分析(REQ)并查看其显示方式。它被人体解析器弄乱了,我有点迷失了。

  cat <<EOF | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job/instance/some_instance
  # TYPE some_metric counter
  some_metric{label="val1"} 42
  # TYPE another_metric gauge
  # HELP another_metric Just an example.
  another_metric 2398.283
  EOF

我在axios中尝试了几种不同的方法,但是都没有用 -https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format

1 个答案:

答案 0 :(得分:0)

       request({
            url: 'http://localhost:9091/metrics/job/interface_data',
            method: 'POST',
            body: 'datahere 10\n',
            encoding: null
        }, (error, response, body) => {
            if (error) {
                console.log(error)
            } else {
                console.log(response)
                console.log('response, ', response.body)
            }
        })

为我工作。诀窍是encoding: null

相关问题