【问题标题】:Convert this cURL command with proxy to a Node.JS code将此带有代理的 cURL 命令转换为 Node.JS 代码
【发布时间】:2017-12-31 23:51:18
【问题描述】:

我有以下 cURL 命令:

curl.exe -X GET -k _https://url --proxy proxy.example:80 --proxy-user "user:password" 

我一直在尝试使用 global-tunnel 之类的全局代理或 node-tunnel 之类的东西,但我不知道它是否正确

问题是如何在 Node.js 代码中转换这个 curl 命令

我想这一定是一个简单的解决方案,但我想不通

【问题讨论】:

  • 您的问题是什么?是吗,使用代理是否是正确的方法?你想完成什么?
  • 问题是如何把这个curl命令转换成Node.js代码

标签: javascript node.js curl proxy


【解决方案1】:

我会使用request 库。

import request from 'request'
const params = {
  method: 'GET',
  url: 'https://url',
  proxy: 'http://user:password@proxy.example:80'
}
request(params, (err, result) => {
  if (err) throw err
  // handle result...
})

【讨论】:

  • 你是个天才。非常感谢。
  • 顺便说一句,现在不推荐使用请求库,请改用 axios。它现在是推荐的,并且有一个类似的 api。
猜你喜欢
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 2013-05-23
  • 1970-01-01
  • 1970-01-01
  • 2016-03-07
相关资源
最近更新 更多