Skip to content

Instantly share code, notes, and snippets.

@starkhorn
Created October 24, 2012 11:07
Show Gist options
  • Save starkhorn/3945492 to your computer and use it in GitHub Desktop.
Save starkhorn/3945492 to your computer and use it in GitHub Desktop.
Node.js: HTTP request behind an authorized proxy
http = require "http"
proxy =
host: "xxx.xxx.xxx.xxx"
port: 8080
username: "username"
password: "password"
auth: -> "Basic " + new Buffer(@username + ":" + @password).toString("base64")
url = require("url").parse "http://search.twitter.com/search.json?q=starkhorn"
http.request
host: proxy.host
port: proxy.port
path: url.href
headers:
"Proxy-Authorization": proxy.auth()
"Host": url.host
, (res) ->
body = ""
res.setEncoding "utf8"
res.on "data", (chunk) ->
body += chunk
res.on "end", ->
console.log JSON.parse body
.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment