Bert Johnson » Blog »

.NET Proxy

I just added a new project to CodePlex:

https://netproxy.codeplex.com/

.NET Proxy consists of two components: an ASPX page for proxying requests to other servers and a JavaScript class for issuing cross-domain requests using the same syntax as XMLHttpRequest. I see it being useful for two scenarios:

SSL Proxy

Example

Requests for https://example.com would become requests for netproxy.aspx?https://example.com.

JavaScript Proxy

Another common goal is to incorporate content from third-party sites, but JavaScript has a “same origin policy” restriction meaning you can only access files on your own domain. With this proxy, you can GET content from or POST content to any server in the world using the familiar XMLHttpRequest syntax. All methods and properties are wrapped, meaning only the object declaration needs to be changed.

Example

// Pass in the URL for our proxy ASPX page
var bingProxy = new netProxy("netProxy.aspx");
bingProxy.onreadystatechange = function() {
if (bingProxy.readyState == 4)
alert('Source code for https://bing.com:\r\n\r\n' + bingProxy.responseText);
}
bingProxy.open("GET", "https://bing.com", true);
bingProxy.send();

It’s released under the MIT License, meaning you can do pretty much anything you want with it.