using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
namespace Proxy {
public partial class _Proxy : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
string proxyURL = string.Empty;
try {
proxyURL = HttpUtility.UrlDecode(Request.QueryString["u"].ToString());
}
catch { }
if (proxyURL != string.Empty) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(proxyURL);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode.ToString().ToLower() == "ok") {
string contentType = response.ContentType;
Stream content = response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
Response.ContentType = contentType;
Response.Write(contentReader.ReadToEnd());
}
}
}
}
}
<%@ Page Language="C#"
AutoEventWireup="true"
CodeBehind="Proxy.aspx.cs"
Inherits="Proxy._Proxy" %>
http://www.yourdotnetapplication.com/proxy.aspx?u=http%3a%2f%2fwww.google.com
http://www.yoursharepointsite.com/_layouts/proxy.aspx?u=http%3a%2f%2fwww.google.com
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (3)
Commented:
https://developer.mozilla.org/en/HTTP_access_control , most browsers won't have any difficulty requesting the content / need the proxy solution above.
If your REMOTE server is running Apache you can achieve this by loading the "headers" module and adding something along the following lines to the remote httpd.conf:
Open in new window
If you don't have access to the remote server, and your LOCAL web server is Apache based, you can achieve the above functionality, plus a bit more, by using the "proxy" module to set-up a ReverseProxy. Just add something along the following lines to your local httpd.conf, and replace any URL's of the form "http://www.some.webservice/remote_script.php", in the javaScript with: "/proxy/remote_script.php"
Note: In addition to GET's this proxy solution will also handle any POST or OPTIONS submissions from the Browser, may be useful if your trying to add something like an: Exchange Rate , Stock Price, or Delivery rate Lookup form / function to your site.
If your running IIS and need to support more than a GET request, then the following ASP.NET solution may be of some interest: http://www.codeproject.com/KB/web-security/HTTPReverseProxy.aspx
Commented:
I mentioned this also in my Article Cross-Site Exploitations which is something to keep in mind when opening up this functionality.
By the way, you have my Yes vote above.
Kevin
Commented:
http://www.codeproject.com/KB/scripting/easyXDM.aspx
Kind Regards,