You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用node-libcurl设置Origin请求头?含cURL示例及当前代码

How to Set Origin Request Header with node-libcurl's curly

Got it, adding an Origin header using curly is super similar to how you do it with cURL—you just need to pass a headers object as part of the options in your curly.get() call.

Here's how to modify your existing code to include the Origin header, matching the cURL example you provided:

const { curly } = require('node-libcurl')

async function test(){
  // Pass headers via the options object as the second argument
  const mm = await curly.get('https://example.com', {
    headers: {
      'Origin': 'http://foo.bar.com'
    }
  })
  console.log(mm)
}

test()

Quick breakdown:

  • The second parameter in curly.get() accepts an options object, where we define the headers property.
  • Each key-value pair in the headers object maps directly to a request header—just like the -H flag in cURL. This specific setup is equivalent to running curl -H "Origin: http://foo.bar.com" --verbose https://example.com.

If you want to add verbose logging (to match the --verbose flag in your cURL example), you can also add the verbose: true option to the object:

const mm = await curly.get('https://example.com', {
  headers: {
    'Origin': 'http://foo.bar.com'
  },
  verbose: true
})

内容的提问来源于stack exchange,提问作者imaginate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:30:42