Created
October 24, 2012 11:07
-
-
Save starkhorn/3945492 to your computer and use it in GitHub Desktop.
Node.js: HTTP request behind an authorized proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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