代码之家  ›  专栏  ›  技术社区  ›  rickythefox

如何为JSONP调用构建ASPX代理页

  •  0
  • rickythefox  · 技术社区  · 15 年前

    我在本地Intranet上有一个页面,它以JSONP格式提供信息,并希望外部用户能够使用该页面进行Ajax调用。

    为此,我想编写一个ASPX代理页面,将客户机请求传递到内部页面(在另一台服务器上),然后将未更改的响应发送到外部客户机。

    最简单的方法是什么?

    2 回复  |  直到 15 年前
        1
  •  0
  •   rickythefox    15 年前

    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();
    
        2
  •  0
  •   Undo ptrk    10 年前

    *.ashx