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
)
精彩评论