rickythefox rickythefox - 1 year ago 167
Ajax Question

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 this 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?

Answer Source

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.ContentType = "application/json";
        Response.ContentEncoding = Encoding.UTF8;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download