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

允我心安 提交于 2019-12-03 16:00:02

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

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.

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