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

落花浮王杯 提交于 2019-12-21 05:00:57

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/1280739/how-can-i-make-a-very-simple-web-proxy-using-asp-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!