开发者

How to build a ASPX proxy page for JSONP calls

I have a page on the local intranet that provides information in JSONP format and want external users to be able to use that page for AJAX calls.

For 开发者_StackOverflowthis I want to write an ASPX proxy page that passes the client request to the internal page (on another server) and then sends the unaltered response to the external client.

What would be the easiest way to accomplish this?


Solved this using the following code in Page_Load:

        var request = (HttpWebRequest)WebRequest.Create("http://jsonsource/");
        var response = (HttpWebResponse) request.GetResponse();
        var json = new StreamReader(response.GetResponseStream()).ReadToEnd();

        Response.ClearHeaders();
        Response.ClearContent();
        Response.Clear();
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/json";
        Response.ContentEncoding = Encoding.UTF8;
        Response.Write(json);
        Response.Flush();


Use a Generic Handler (*.ashx)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜