How can I make a VERY simple web proxy using ASP.NET?

I am going to run a site that worked well until I find the following hiccups:

I can not request Yahoo! Pipe over SSL.

Thus, pages that require SSL now miss some of their functionality if I don’t figure out how to do this; obviously this can be done if i use the SSL enabled page in my application to request Yahoo! for me.

I have seen solutions like http://www.iisproxy.net/license.html , but it seems to be a little hard on what I'm trying to do.

Can't I do this with a simple ASHX handler? Or is it harder than that?

Thanks,

Michael

+5
source share
2 answers

I think if all you want to do is read the contents of the request, you can use WebRequest and WebResponse

here are some details about using this

http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm

+1
source

Thanks, John - in case this helps someone else, here is the code I use in my ASHX file:

   public override void ProcessRequest(HttpContext context)
    {
        var strURL = context.Server.UrlDecode(context.Request["url"]);

        WebResponse objResponse = default(WebResponse);
        WebRequest objRequest = default(WebRequest);
        string result = null;
        objRequest = HttpWebRequest.Create(strURL);
        objResponse = objRequest.GetResponse();
        StreamReader sr = new StreamReader(objResponse.GetResponseStream());
        result = sr.ReadToEnd();
        //clean up StreamReader 
        sr.Close();

        //WRITE OUTPUT
        context.Response.ContentType = "application/json";
        context.Response.Write(result);
        context.Response.Flush();

    }

However, I received a couple of extra characters (unlike the version that came straight from Yahoo! Pipes), so I had to delete them before parsing JSON.

+4
source

All Articles