如何使用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 theheadersproperty. - Each key-value pair in the
headersobject maps directly to a request header—just like the-Hflag in cURL. This specific setup is equivalent to runningcurl -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
相关产品推荐
相关产品推荐

