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

2019-03-29 13:56发布

I'm about to launch a site that was working well until I found the following hiccup:

I can't request a Yahoo! Pipe over SSL.

So the pages that require SSL are now missing a piece of their functionality unless I figure out a way around this; obviously, this could be done if I use an SSL-hosted page on my app to request the Yahoo! pipe for me.

I've seen solutions like http://www.iisproxy.net/license.html, but it seems to be a bit heavy for what I'm trying to do.

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

Thank you,

Michael

2条回答
Bombasti
2楼-- · 2019-03-29 14:05

Thank you, John -- in case it's helpful to anyone else, here's the code I'm using 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 was getting a couple extra characters (as opposed to the version that came direct from Yahoo! Pipes), so I had to remove those before parsing the JSON.

查看更多
你好瞎i
3楼-- · 2019-03-29 14:10

I guess if all you want to do is read the contents of a request you could use a WebRequest & WebResponse

here are some details on using that

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

查看更多
登录 后发表回答