MCPcopy Create free account
hub / github.com/nodejs/undici / fetchWithSocks5Example

Function fetchWithSocks5Example

docs/examples/socks5-proxy.js:57–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55
56// Example with fetch API
57async function fetchWithSocks5Example () {
58 console.log('\n=== Fetch with SOCKS5 Proxy Example ===')
59
60 try {
61 const socks5Proxy = new Socks5Agent('socks5://localhost:1080')
62
63 const response = await fetch('http://httpbin.org/json', {
64 dispatcher: socks5Proxy
65 })
66
67 console.log('Status:', response.status)
68 const data = await response.json()
69 console.log('JSON data:', data)
70
71 await socks5Proxy.close()
72 } catch (error) {
73 console.error('Error:', error.message)
74 }
75}
76
77// Example with HTTPS
78async function httpsWithSocks5Example () {

Callers 1

runExamplesFunction · 0.85

Calls 4

fetchFunction · 0.85
jsonMethod · 0.65
closeMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected